当前位置:首页 » 编程语言 » c语言结构体数组能不能交换
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言结构体数组能不能交换

发布时间: 2022-10-19 19:16:06

1. 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;

2. c语言结构体数组怎么交换

定义一个struct cj temp;
然后就直接交换啊。

我把那块做成函数,楼主直接调用吧,主函数就没写完整了。

#include <stdio.h>
struct cj
{
int No;
char Name[20];
int cj1;
int cj2;
int cj3;
int pingjun;
int Number;
};
int main(int argc, char *argv[])
{
struct cj student[50];
void sort(struct cj *student,int n);
sort(student,50);
return 0;
}

void sort(struct cj *student,int n)/*从大到小的*/
{
int flag;
int i,j;
struct cj temp;
for(i=0;i<n-1;i++)
{
flag=0;
for(j=0;j<n-i-1;j++)
if(student[j].pingjun<student[j+1].pingjun)
{
flag=1;
temp=student[j+1];
student[j+1]=student[j];
student[j]=temp;
}
if(flag==0)
break;
}
}

3. 如何交换结构体数组中两个项的内容

可以自己加个索引值来表示当前数组元素的个数
p_veh=new INFO_VEH[iAll];
int nIndex = 0;
p_veh[nIdex].xx = xx
...
++nInde;

4. c语言如何 把结构体内的变量的值互换

同类型结构体间可以直接赋值
struct phoneinfor s1,s2,temp;
temp=s1;
s1=s2;
s2=temp;
你这个不行:
if(strcmp(phonebook[j].name,phonebook[j+1].name)>0)
{
phonebook3=phonebook[j];
//phonebook3是phoneinfor3类型的,你得把它定义为phoneinfor类型的
phoneinforphonebook[j]=phonebook[j+1];
phonebook[j+1]=phonebook3;
}

5. c语言中怎样交换两个数组

逐个元素交换即可。

前提是两个数组必须有同样的长度

否则无法交换。

函数如下:

voidswap_array(int*a,int*b,intl)
{
inti,t;
for(i=0;i<l;i++)
{
t=a[i];
a[i]=b[i];
b[i]=t;
}
}

构建好两个等长数组,调用这个函数就可以

a和b是两个数组名, l为数组元素个数,即长度。

6. 结构体数组的变量怎么交换

#define N 5
struct student1
{
long num;
char name[10];
int sorce[2];
int total;
}student[N];
main()
{
int i, j;
struct student1 temp;
printf("请输入学生的基本信息");
printf("num\tname\tsorce1\tsorce2\n");
for (i = 0; i < N; i++)
{
scanf_s("%ld,%s,%d,%d", &student[i].num, student[i].name,10, &student[i].sorce[0], &student[i].sorce[1]);
student[i].total = student[i].sorce[1] + student[i].sorce[0];
}
for (i = 0; i<N - 1; i++)
for (j = 0; j<N - i - 1; j++)
if (student[j].total < student[j + 1].total)
{
temp = student[j];
student[j] = student[j + 1];
student[j + 1] = temp;

} for (i = 0; i < N; i++) printf("%ld\n%s\n%d\n%d\n%d", student[i].num, student[i].name, student[i].sorce[0], student[i].sorce[1], student[i].total); system("pause");

}

7. c语言中交换两个结构体的值

字符串不能用等号赋值

因此你上面注释掉的三行是不正确的

可以用memcpy 或者 strcpy

反正方式你也看明白了

都是 变量交换

8. C语言关于两个结构体中所有值互换的问题

~~~~简单·~~ 假如你要交换结构体A和结构体B的内容,直接定义一个临时结构体。。

STU t;
t=A;
A=B;
B=t;

即可·~~

9. C语言结构体数组怎么交换数据呀!

结构体如果都要集体交换的话,建议使用 memcpy(); 这个函数,新建个中间结构体.. 就可以了, 这个函数有3个参数,具体请网络