㈠ c語言數值的交換
1
a
b中oxa23錯誤;c
4c1.5錯誤;d
10,000錯誤
2
c
for是關鍵字不能他用。
3
b
(1/2)*(a+b)*h中(1/2)直接為0,要想一樣應該為:(1.0/2)或(1/2.0)
4
d
k+1沒有改變k的值。
5
d
kk>=48
&&
kk<91,這個范圍的符號不僅有大寫字母還有別的。
6.正確,這是因為putchar()包含在改頭文件中。
n=n/10;
㈡ c語言數組元素交換問題
數組交換的swap函數中
voidSWAP(double*a,double*b)//用於交換數組的元素
{
doubletemp;
temp=*a;
*a=*b;
*b=temp;
}
你傳進去的是double*a
但你定義的是doubletemp
類型都不一樣怎麼賦值!!
㈢ C語言編程 函數實現數組行列互換
for(i=0;i<i;i++)
兄弟,這句話錯了,應該是for(i=0;i<3;i++)
printf("處理後的數組為 ")
這句話少了一個分號
printf(" ")這個也是少分號
㈣ C語言使用指針函數進行數組互換問題
你這個只是試圖交換兩個數組的首地址,而數組的首地址是常量,不會交換成功的。
你的swap中要用循環一次交換兩個數組的對應元素才能實現你想要的功能。
㈤ c語言怎樣交換兩個數組 用swap函數
void swap_array(int *pa,int *pb);
main(){
int x[]={0,1,2,3,4};
int y[]={5,6,7,8,9};
swap_array(x,y);
int i;
for(i=0;i<5;i++)
printf("%d",x[i]);
printf("\r\n",x[i]);
for(i=0;i<5;i++)
printf("%d",y[i]);
scanf("%d",&i);
}
void swap_array(int *pa,int *pb){
int n;
n= sizeof(pa);
int c;
int i;
for(i=0;i<=n;i++){
c=*pa;
*pa=*pb;
*pb=c;
++pa;
++pb;}
}
㈥ C語言,定義函數交換字元串數組
C語言中交換兩個字元串需要藉助strcpy函數或者使用自定義交換函數進行交換
如交換a,b數組中的字元串代碼:
char a[10] = "abed", b[10] = "efg", t[10];strcpy(t, a);//a復制給tstrcpy(a, b);//b復制給astrcpy(b, t);//t復制給b
附:strcpy函數詳情
原型聲明:
char *strcpy(char* dest, const char *src);
頭文件:
#include <string.h> 和 #include <stdio.h>
功能:把從src地址開始且含有NULL結束符的字元串復制到以dest開始的地址空間
說明:src和dest所指內存區域不可以重疊且dest必須有足夠的空間來容納src的字元串。返回指向dest的指針。
㈦ c語言用指針和自定義函數實現數組元素的調換
#include <stdio.h>
#define N 10
void Swap ( int *a, int *b, int n);
int main(void)
{
int *a, *b;
int num1[N], num2[N];
for (a = num1; a < num1 + N; a++)
scanf ("%d", a);
for (b = num2; b < num2 + N; b++)
scanf ("%d", b);
a = num1;//重新指向首地址
b = num2;//重新指向首地址
Swap (a, b, N);
printf ("*********交換後**********\n");
for (a = num1; a < num1 + N; a++)
printf ("%3d", *a);
printf ("\n");
for (b = num2; b < num2 + N; b++)
printf ("%3d", *b);
return 0;
}
void Swap (int *a, int *b, int n)
{
int temp;
int i;
for (i = 0; i < n; i++)
{
temp = *(a + i);
*(a + i) = *(b + i);
*(b + i) = temp;
}
}
㈧ c語言中有沒有交換兩個數組中內容的函數
使用memcpy直接將數組中的數據進行交換。
inta[100],b[100];
intt[100];
memcpy(t,a,sizeof(a));
memcpy(a,b,sizeof(b));
memcpy(b,t,sizeof(t));
㈨ C語言中數組元素互換的問題
當index為0時,數組中下標為0的和下標為4-0的元素交換,也就是第一個和最後一個交換,(1,5)交換
當index為1時,數組中下標為1的和下標為4-1的元素交換,也就是第二個和倒數第二個交換,(2,4)交換
因為此數組元素的個數為奇數個,所以,最中間那個沒有必要交換,所以3原地不動
最後交換後的元素順序為54321