C语言求解!!!
写出下列程序的结果________________.#include<stdio.h>main(){chars[]=”ABCCDA”;intk;charc;for(k=1...
写出下列程序的结果________________.
#include<stdio.h>
main( )
{ char s[]=”ABCCDA”;
int k; char c;
for(k=1;(c=s[k])!=’\0’;k++ )
{ switch (c)
{ case ‘A’: putchar(‘%’);
continue;
case ‘B’: ++k; break;
default: putchar (‘*’);
case ‘C’: putchar(‘&’);
continue; }
putchar (‘#’); }
} 展开
#include<stdio.h>
main( )
{ char s[]=”ABCCDA”;
int k; char c;
for(k=1;(c=s[k])!=’\0’;k++ )
{ switch (c)
{ case ‘A’: putchar(‘%’);
continue;
case ‘B’: ++k; break;
default: putchar (‘*’);
case ‘C’: putchar(‘&’);
continue; }
putchar (‘#’); }
} 展开
3个回答
展开全部
改好了,自己研究一下吧,多练习,提高基础知识
#include<stdio.h>
#include<math.h>
struct clas
{
char name[20]; //名字是个字符串,要用字符数组
int iden;
int mark[4];
int stutotal;
float stuaverage; //平均分有可能不是整数,改为float
};
struct sub
{
int subtotal ;
float subaver; //平均分有可能不是整数,改为float
};
void sort(int, struct clas *);
int main()
{
int i, j;
struct clas student[10];
struct sub subject[4];
printf ("请输入学生的学号,姓名,语文、数学、外语、理综成绩\n");
for (i = 0; i < 10; i++)
{
scanf("%d %s", &(student[i].iden), student[i].name);
student[i].stutotal=0 ; //先要给个初值
for (j = 0; j < 4; j++)
{
scanf("%d", &(student[i].mark[j]) ); //这里是给每一门课赋值 , j
student[i].stutotal += student[i].mark[j];
}
student[i].stuaverage = student[i].stutotal / 4.0; //因为是浮点数,不要整除
}
sort(10, student);
for (j = 0; j < 4; j++)
{
subject[j].subtotal = 0 ; //先要给个初值
for (i = 0; i < 10; i++)
subject[j].subtotal += student[i].mark[j];
subject[j].subaver = (subject[j].subtotal) / 10.0; //因为是浮点数,不要整除
}
for (i = 0; i < 10; i++)
printf("学号为%d的学生的平均成绩为%.2f\n", student[i].iden, student[i].stuaverage);
for (j = 0; j < 4; j++)
printf("学科号%d的平均成绩为%.2f\n", j + 1, subject[j].subaver) ;
return 0;
}
void sort(int m, struct clas *x)
{
int i, j , min;
struct clas tmp;
for (i = 0; i < m-1; i++)
{
min=i ;
for (j = i+1; j < m; j++)
if ( x[j].stuaverage < x[min].stuaverage )
min = j ;
if ( min != i )
{
tmp = x[i] ;
x[i] = x[min];
x[min] = tmp;
}
}
}
以上回答你满意么?
#include<stdio.h>
#include<math.h>
struct clas
{
char name[20]; //名字是个字符串,要用字符数组
int iden;
int mark[4];
int stutotal;
float stuaverage; //平均分有可能不是整数,改为float
};
struct sub
{
int subtotal ;
float subaver; //平均分有可能不是整数,改为float
};
void sort(int, struct clas *);
int main()
{
int i, j;
struct clas student[10];
struct sub subject[4];
printf ("请输入学生的学号,姓名,语文、数学、外语、理综成绩\n");
for (i = 0; i < 10; i++)
{
scanf("%d %s", &(student[i].iden), student[i].name);
student[i].stutotal=0 ; //先要给个初值
for (j = 0; j < 4; j++)
{
scanf("%d", &(student[i].mark[j]) ); //这里是给每一门课赋值 , j
student[i].stutotal += student[i].mark[j];
}
student[i].stuaverage = student[i].stutotal / 4.0; //因为是浮点数,不要整除
}
sort(10, student);
for (j = 0; j < 4; j++)
{
subject[j].subtotal = 0 ; //先要给个初值
for (i = 0; i < 10; i++)
subject[j].subtotal += student[i].mark[j];
subject[j].subaver = (subject[j].subtotal) / 10.0; //因为是浮点数,不要整除
}
for (i = 0; i < 10; i++)
printf("学号为%d的学生的平均成绩为%.2f\n", student[i].iden, student[i].stuaverage);
for (j = 0; j < 4; j++)
printf("学科号%d的平均成绩为%.2f\n", j + 1, subject[j].subaver) ;
return 0;
}
void sort(int m, struct clas *x)
{
int i, j , min;
struct clas tmp;
for (i = 0; i < m-1; i++)
{
min=i ;
for (j = i+1; j < m; j++)
if ( x[j].stuaverage < x[min].stuaverage )
min = j ;
if ( min != i )
{
tmp = x[i] ;
x[i] = x[min];
x[min] = tmp;
}
}
}
以上回答你满意么?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询