每天printf printf printf ~~~~~~~~~~~~~~~~~~~
每天for for for for for ~~~~~~~~~~~~~~~~~~
总有一天我们自己也得成为一个死循环!!!!!
while(1) while(1) while(1) while(1) ~~~~~~~~~~~~~~~
看看我悲催的成绩排序作业吧!哎,无赖写这么无聊的程序!当然,我们也只会写这样的!
#include<stdio.h>
#define STU 3
#define NUM 2
void stu_ave(int arr[STU][NUM]);
void input_far(int arr[STU][NUM]);
void stu_ave_stor(int arr[STU][NUM]);
void stu_subject(int arr[STU][NUM]);
void stu_60(int arr[STU][NUM]);
void out_menu(void);
int menu(char x);
void error(int err);
int main(void){
static int stu_arr[STU][NUM],flag,i=1,err;
char x;
out_menu();
while(i++){
if(i!=2)out_menu();else printf("Now you should input the array number,please input 'N'.\n");
error(err);
err=0;
printf("Cmd:_\b");
x=getchar();
while(x=='\n'){
x=getchar();
}
flag=menu(x);
if(flag==0)break;
if(flag==1)input_far(stu_arr);
if(flag==2)stu_ave(stu_arr);
if(flag==3)stu_subject(stu_arr);
if(flag==4)stu_ave_stor(stu_arr);
if(flag==5)stu_60(stu_arr);
if(flag==100)err=1;
}
return 0;
}
void error(int err){
if(err!=0)printf("ERROR:");
switch(err){
case 1:printf("Input error!please check.\n");break;
}
}
int menu(char x){
int flag;
switch(x){
case 'x':case 'X':flag=0;break;
case 'N':case 'n':flag=1;break;
case 'E':case 'e':flag=2;break;
case 'S':case 's':flag=3;break;
case 'P':case 'p':flag=4;break;
case 'T':case 't':flag=5;break;
default:flag=100;
}
return flag;
}
void out_menu(void){
printf("------------------------------------------------------------------\n"
"---- ( N/n ) Input student farction.------------------------------\n"
"---- ( E/e ) Output student average.------------------------------\n"
"---- ( S/s ) Out subject average.---------------------------------\n"
"---- ( P/p ) Stor student of average.-----------------------------\n"
"---- ( T/t ) Out no pass student.---------------------------------\n"
"---- ( X/x ) Exit programe.---------------------------------------\n"
"------------------------------------------------------------------\n");
}
void input_far(int arr[STU][NUM]){
int i,j;
for(i=0;i<STU;i++){
printf("Input the %drd student %d subject farction:",i+1,NUM);
for(j=0;j<NUM;j++)scanf("%d",&arr[i][j]);
}
}
void stu_ave(int arr[STU][NUM]){
int i,j;float sum;
for(i=0;i<STU;i++){
sum=0;
for(j=0;j<NUM;j++)
sum+=arr[i][j];
printf("The %drd student average is %.2f\n",i+1,sum/NUM);
}
}
void stu_subject(int arr[STU][NUM]){
int i,j;float sum;
for(i=0;i<NUM;i++){
sum=0;
for(j=0;j<STU;j++)
sum+=arr[j][i];
printf("The %drd subject average is %.2f\n",i+1,sum/STU);
}
}
void stu_ave_stor(int arr[STU][NUM]){
static float stu_in[STU][3];//定义学生平均分和学号对应的数组
int i,j;
float sum,t;
for(i=0;i<STU;i++){
sum=0;
for(j=0;j<NUM;j++)sum+=arr[i][j];
stu_in[i][0]=(float)i;
stu_in[i][1]=sum;
stu_in[i][2]=sum/NUM;
}
//成绩排列
for(i=0;i<STU;i++){
for(j=i;j<STU-1;j++)
if(stu_in[j][1]<stu_in[j+1][1]){
t=stu_in[j][0];
stu_in[j][0]=stu_in[j+1][0];
stu_in[j+1][0]=t;
t=stu_in[j][1];
stu_in[j][1]=stu_in[j+1][1];
stu_in[j+1][1]=t;
t=stu_in[j][2];
stu_in[j][2]=stu_in[j+1][2];
stu_in[j+1][2]=t;
}
}
//格式化输出平均分排列表
printf("\n");
printf("num_ID");
for(i=0;i<NUM;i++)printf(" sub%2d",i+1);
printf(" sum ave\n");
for(i=0;i<STU;i++){
printf("%5.0f",stu_in[i][0]);
for(j=0;j<NUM;j++)printf("%8d",arr[(int)stu_in[i][0]][j]);
printf("%9.0f%9.2f\n",stu_in[i][1],stu_in[i][2]);
}
}
void stu_60(int arr[STU][NUM]){
int i,j,k,sum;
static int stu_info[STU][NUM+2];
for(i=0;i<STU;i++){
for(j=0,sum=0,k=0;j<NUM;j++){
if(arr[i][j]<60)stu_info[i][j]=0,k+=1;
else stu_info[i][j]=1;
sum+=arr[i][j];
}
stu_info[i][NUM]=sum;
stu_info[i][NUM+1]=k;
}
for(i=0;i<STU;i++){
if(stu_info[i][NUM+1]==0)printf("ID:%d ALL pass ,sum=%d. ",i,stu_info[i][NUM]);
else {
printf("ID:%d %d subject no pass: ",i,stu_info[i][NUM+1]);
for(j=0;j<NUM;j++)if(stu_info[i][j]==0)printf("sub %d no pass,",j);
if(stu_info[i][NUM]<(NUM*60))printf(" sum no pass ,sum=%d.",stu_info[i][NUM]);
}
printf("\n");
}
}
#define STU 3
#define NUM 2
void stu_ave(int arr[STU][NUM]);
void input_far(int arr[STU][NUM]);
void stu_ave_stor(int arr[STU][NUM]);
void stu_subject(int arr[STU][NUM]);
void stu_60(int arr[STU][NUM]);
void out_menu(void);
int menu(char x);
void error(int err);
int main(void){
static int stu_arr[STU][NUM],flag,i=1,err;
char x;
out_menu();
while(i++){
if(i!=2)out_menu();else printf("Now you should input the array number,please input 'N'.\n");
error(err);
err=0;
printf("Cmd:_\b");
x=getchar();
while(x=='\n'){
x=getchar();
}
flag=menu(x);
if(flag==0)break;
if(flag==1)input_far(stu_arr);
if(flag==2)stu_ave(stu_arr);
if(flag==3)stu_subject(stu_arr);
if(flag==4)stu_ave_stor(stu_arr);
if(flag==5)stu_60(stu_arr);
if(flag==100)err=1;
}
return 0;
}
void error(int err){
if(err!=0)printf("ERROR:");
switch(err){
case 1:printf("Input error!please check.\n");break;
}
}
int menu(char x){
int flag;
switch(x){
case 'x':case 'X':flag=0;break;
case 'N':case 'n':flag=1;break;
case 'E':case 'e':flag=2;break;
case 'S':case 's':flag=3;break;
case 'P':case 'p':flag=4;break;
case 'T':case 't':flag=5;break;
default:flag=100;
}
return flag;
}
void out_menu(void){
printf("------------------------------------------------------------------\n"
"---- ( N/n ) Input student farction.------------------------------\n"
"---- ( E/e ) Output student average.------------------------------\n"
"---- ( S/s ) Out subject average.---------------------------------\n"
"---- ( P/p ) Stor student of average.-----------------------------\n"
"---- ( T/t ) Out no pass student.---------------------------------\n"
"---- ( X/x ) Exit programe.---------------------------------------\n"
"------------------------------------------------------------------\n");
}
void input_far(int arr[STU][NUM]){
int i,j;
for(i=0;i<STU;i++){
printf("Input the %drd student %d subject farction:",i+1,NUM);
for(j=0;j<NUM;j++)scanf("%d",&arr[i][j]);
}
}
void stu_ave(int arr[STU][NUM]){
int i,j;float sum;
for(i=0;i<STU;i++){
sum=0;
for(j=0;j<NUM;j++)
sum+=arr[i][j];
printf("The %drd student average is %.2f\n",i+1,sum/NUM);
}
}
void stu_subject(int arr[STU][NUM]){
int i,j;float sum;
for(i=0;i<NUM;i++){
sum=0;
for(j=0;j<STU;j++)
sum+=arr[j][i];
printf("The %drd subject average is %.2f\n",i+1,sum/STU);
}
}
void stu_ave_stor(int arr[STU][NUM]){
static float stu_in[STU][3];//定义学生平均分和学号对应的数组
int i,j;
float sum,t;
for(i=0;i<STU;i++){
sum=0;
for(j=0;j<NUM;j++)sum+=arr[i][j];
stu_in[i][0]=(float)i;
stu_in[i][1]=sum;
stu_in[i][2]=sum/NUM;
}
//成绩排列
for(i=0;i<STU;i++){
for(j=i;j<STU-1;j++)
if(stu_in[j][1]<stu_in[j+1][1]){
t=stu_in[j][0];
stu_in[j][0]=stu_in[j+1][0];
stu_in[j+1][0]=t;
t=stu_in[j][1];
stu_in[j][1]=stu_in[j+1][1];
stu_in[j+1][1]=t;
t=stu_in[j][2];
stu_in[j][2]=stu_in[j+1][2];
stu_in[j+1][2]=t;
}
}
//格式化输出平均分排列表
printf("\n");
printf("num_ID");
for(i=0;i<NUM;i++)printf(" sub%2d",i+1);
printf(" sum ave\n");
for(i=0;i<STU;i++){
printf("%5.0f",stu_in[i][0]);
for(j=0;j<NUM;j++)printf("%8d",arr[(int)stu_in[i][0]][j]);
printf("%9.0f%9.2f\n",stu_in[i][1],stu_in[i][2]);
}
}
void stu_60(int arr[STU][NUM]){
int i,j,k,sum;
static int stu_info[STU][NUM+2];
for(i=0;i<STU;i++){
for(j=0,sum=0,k=0;j<NUM;j++){
if(arr[i][j]<60)stu_info[i][j]=0,k+=1;
else stu_info[i][j]=1;
sum+=arr[i][j];
}
stu_info[i][NUM]=sum;
stu_info[i][NUM+1]=k;
}
for(i=0;i<STU;i++){
if(stu_info[i][NUM+1]==0)printf("ID:%d ALL pass ,sum=%d. ",i,stu_info[i][NUM]);
else {
printf("ID:%d %d subject no pass: ",i,stu_info[i][NUM+1]);
for(j=0;j<NUM;j++)if(stu_info[i][j]==0)printf("sub %d no pass,",j);
if(stu_info[i][NUM]<(NUM*60))printf(" sum no pass ,sum=%d.",stu_info[i][NUM]);
}
printf("\n");
}
}
完全看不懂的路过,不过看你大学生活很丰富,哈哈,还要学太极。
天天做PPT叫丰富??
学python吧,和其他语言一对比,就会喜欢上它
python的语法格式看着就想吐,多一个tab就出错,简直
c语言我在上计算机函授时学了一点点,太费心了
还好啦!
我也讨厌C语言,每次上课都偷偷睡觉
结果呢!?
天冷了,多加保暖~
可以自己更进一步的说