C语言程序求助!

作者&投稿:招蓉 (若有异议请与网页底部的电邮联系)
C语言程序求助~

/*1.按要求输入界面;2.按要求输入班级人数并判断大/小班,判断规则:5人以上为大班,5人及以下为小班;3.通过键盘输入班级学生的成绩;4.判断学生成绩是否合格,并输出。判断规则:60分以下不及格输出“补考”,60-79分输出“合格”,80-100分输出“优秀”,负分数和100分以上显示“错误”。5.求学生成绩的最高分;6.并计算该班级学生的总分和平均成绩并显示,规则:负分数和100分以上显示“错误”的分数不计数总分及平均成绩计算中;程序结束界面输出。*/#include "stdio.h"#include "math.h"#include "string.h"void inquire_Num();void init_Cls();void inset_Grade();struct score{float chinese;float math;float english;};struct student{int id; char name[10];char sex[2];struct score sc;};struct cls{struct student stu[10];int Cls_number;int stu_Num;//学生人数};struct cls ClsNum[5];void main(){int choose=0;printf("/***********************************/
");printf("/* 1、班级属性 */
");printf("/* 2、输入成绩 */
");printf("/* 3、判断合格 */
");printf("/* 4、求最高分 */
");printf("/* 5、求平均分 */
");printf("/***********************************/
");printf("请输入对应的序号(1--5)
");scanf("%d",&choose);init_Cls();switch(choose){case 1:inquire_Num();break;case 2:inset_Grade();break;}system("pause");}void init_Cls(){//一班ClsNum[0].Cls_number=1;ClsNum[0].stu_Num=5;ClsNum[0].stu[0].id=1;strcpy(ClsNum[0].stu[0].name,"卫庄");strcpy(ClsNum[0].stu[0].sex,"男");ClsNum[0].stu[0].sc.chinese=80.5;ClsNum[0].stu[0].sc.math=88.5;ClsNum[0].stu[0].sc.english=90.5;ClsNum[0].stu[1].id=2;strcpy(ClsNum[0].stu[1].name,"李斯");strcpy(ClsNum[0].stu[1].sex,"男");ClsNum[0].stu[1].sc.chinese=69.5;ClsNum[0].stu[1].sc.math=70;ClsNum[0].stu[1].sc.english=80;ClsNum[0].stu[2].id=3;strcpy(ClsNum[0].stu[2].name,"韩非");strcpy(ClsNum[0].stu[2].sex,"男");ClsNum[0].stu[2].sc.chinese=100;ClsNum[0].stu[2].sc.math=100;ClsNum[0].stu[2].sc.english=100;ClsNum[0].stu[3].id=4;strcpy(ClsNum[0].stu[3].name,"张良");strcpy(ClsNum[0].stu[3].sex,"男");ClsNum[0].stu[3].sc.chinese=99.5;ClsNum[0].stu[3].sc.math=100;ClsNum[0].stu[3].sc.english=100;ClsNum[0].stu[3].id=5;strcpy(ClsNum[0].stu[4].name,"白凤");strcpy(ClsNum[0].stu[4].sex,"男");ClsNum[0].stu[4].sc.chinese=65;ClsNum[0].stu[4].sc.math=30;ClsNum[0].stu[4].sc.english=50;//二班ClsNum[1].Cls_number=2;ClsNum[1].stu_Num=2;ClsNum[1].stu[0].id=1;strcpy(ClsNum[1].stu[0].name,"姬无夜");strcpy(ClsNum[1].stu[0].sex,"男");ClsNum[1].stu[0].sc.chinese=30;ClsNum[1].stu[0].sc.math=20;ClsNum[1].stu[0].sc.english=30;ClsNum[1].stu[1].id=2;strcpy(ClsNum[0].stu[1].name,"赵高");strcpy(ClsNum[0].stu[1].sex,"男");ClsNum[1].stu[1].sc.chinese=50;ClsNum[1].stu[1].sc.math=90;ClsNum[1].stu[1].sc.english=60;}void inquire_Num(){int Cls_ID;printf("请输入需要查询的班级:
");scanf("%d",&Cls_ID);if(Cls_ID==0||ClsNum[Cls_ID-1].Cls_number==0){printf("该班级不存在");}else{if(ClsNum[Cls_ID-1].stu_Num>=5){printf("%d班级为大班
",Cls_ID);}else{printf("%d班级为小班
",Cls_ID);}}}void inset_Grade(){int clsnumber=0;int stuId=0;float chinese,math,english;printf("请输入需要输入几班的成绩
");scanf("%d",&clsnumber);printf("请输入学生学号
");scanf("%d",&stuId);if(ClsNum[clsnumber-1].Cls_number==0){printf("查无此班");return;}else{if(ClsNum[clsnumber-1].stu[stuId-1].id==0){printf("查无此人");return;}else{printf("请分别输入该学生的语文 数学 英语(用空格隔开)");scanf("%d %d %d",&chinese,&math,&english);ClsNum[clsnumber-1].stu[stuId-1].sc.chinese=chinese;ClsNum[clsnumber-1].stu[stuId-1].sc.math=math;ClsNum[clsnumber-1].stu[stuId-1].sc.math=english;}printf("输入成功
");}}上边是实现了两个功能,其他功能你对照着完善下,没有时间做,毕竟还要上班。下次非常麻烦的代码,你的奖励20可没人做

#include "stdio.h"#include #include "time.h"int main(int argc,char *argv[]){int randList[10],n,l,r,t,i;printf(" Input number: ");scanf("%d",&n);srand((unsigned)time(NULL));for(l=0;lrandList[r+1])t=randList[r],randList[r]=randList[r+1],randList[r+1]=t;printf("Sort array: ");for(l=0;l>1;printf("
Binary Search step: ");for(i=l;irandList[t] ? l=t+1 : r=t-1;}if(l>=r)printf("
NO FOUND!
",n);return 0;}运行样例:

首先看无论while怎么循环k都等于2,b都等于1.
程序开始:w=3进入最外层while循环,j=6,k=2,b=1;
在进入内层循环k<=6/2也就是2<=3为真,逻辑与上b也就是1,结果为真。
k自增为3,b=j%k也就是b=6%3 =0
在进入内层while循环,结果为假,跳过内层循环,进入判断语句。
由于b=0为假,所以执行else,数组list[]={9,7,8,6}. w=2.
第2次外循环:
进入外层while. u<=w 也就是0<=2为真
j=9,k=2,b=1.
进入内层循环,k<=j/2&&b 也就是 2<=9/2&&1 结果为真
k自增为3,b=j%k 也就是b=0 在进入内层while结果为假,进入判断语句
此时数组list={8,7,9,6} w自减为1
第3次外循环:
进入外循环判断 0<=1为真
j=8,k=2,b=1 进入内循环while 2<=8/2&&1 为真
k自增为3,b=8%3 b为2,在进入内循环while 3<=4&&2 为真
k自增为4 b=8%4 =0 在进入内循环while 为假---------------------------------注意这里内循环了2次喔!
进入判断语句 此时list={7,8,9,6} w=0
第4次外循环:
进入外判断while 0<=0 为真
j=7,k=2,b=1 进入内循环while 2<=7/2&&1 结果为真。
k自增为3 b=7%3 =1 进入内循环while 3<=3&&1
k自增为4 b为3 内循环为假
进入if语句
输入始终u=0的数组下表=7
是不是这样的?为啥我测试当w为0时,内循环只有1次呢?

为什么有这么纠结的程序,我无聊一个个的数往里面代入..输出是7,
一个个的代的试嘛! 整个大循环运行四次结束,
w=3

u=0;w=3
j=6;
k=2;
b=1;
k=2; 3 b=1;
k=3;b=0;
list[0]=9;
list[3]=6;w=2

u=0.w=2
j=9
k=2
b=1
{ k=2.4.b=1
3.0.} 这里面是小while里的程序
list[0]=8
list[2]=9.w=1

u=0.w=1
j=8
k=2
b=1
{ k=2.4.b=1
3.2
3.4.2
4.0.}
list[0]=7
list[1]=8.w=0

u=0.w=0
j=7
k=2
b=1
{ k=2.3.b=1
3.1
3.3.1
4.3 }
k=4.j/2=3.b=3
这里4<3不成立,b=3为真,,,,开始执行if语句了
list[0]=7,u=1 w=0
再u<=w
所以输出了7,程序终止了!~

你这个程序没有输出,因为“b=j%k”始终为0,无法进入"if(b)"语句,因此你在W自减4次后就程序跳出“while(u<=w)”循环,没有结果输出。


求助C语言程序调试题目~~~大恩不言谢!!!
1、void panduan(char id): 应该是void panduan(char *id)或void panduan(char id[])2、if(id[16]%2=0) :应该是if(id[16]%2==0)3、scanf("%d",id); :应该是scanf("%s",id);4、panduan(id[]); :应该是panduan(id);...

C语言程序有问题——求助啊~~~
include <stdio.h>void someday(int y,int m,int d); int isLeapYear(int year);int validInput(int y,int m,int d);int main() { \/\/ Start typing your code here... int year,month,day; while(1) { printf("请输入年 月 日(中间以空格隔开):"); scanf(...

编写c语言程序,求助
include <stdio.h> void main(){ struct date { int year;int month;int day;}date1,date2;int age;loap1: printf("Please input the date you born(yyyy\/mm\/dd):\\n");scanf("%d\/%d\/%d",&date1.year,&date1.month,&date1.day);if (date1.month>12||date1.month<0){ printf("...

C语言 写一个人简单的程序,我一菜鸟求助~
include<stdio.h> int main(){ int a[10],i,max;scanf("%d",&a[0]);max = a[0];for ( i = 0 ; i < 10 ; i++ ){ scanf("%d",&a[i]);if ( a[i] > max )max = a[i];} printf("the max one is %d\\n",max);return 0;} ...

Pascal语言程序 求助如何使此程序运行一次后可以继续输入X的数值再次运 ...
把现在这个程序做成子程序,然后在主程序用while\/until或者do\/repeat循环,另外设置个退出条件(例如变量)就行

我们C语言要考试了,让自己编个程序,求助!!
给你个吧,今天在百度上逛时碰到要给这个代码加注释的,呵呵,我加了一点注释。这是个万年历程序,可输入具体日期计算这天是星期几,输出全年的日历,还可以判断是否是闰年。这个程序只是代码比较长,但难度不大,你应该能看读懂。include<stdio.h> include<stdlib.h> char* month_str[]={"January"...

有两个C语言程序没头绪,求助!!!
include <stdio.h> int main(){ int i,n,score;int a[3] = {0,0,0}; \/\/a[0]-优秀,a[1]-及格, a[2]-不及格 printf("输入学生人数:");scanf("%d", &n);for (i=0;i<n;i++) { scanf("%d", &score);if (score>=85) a[0]++;else if (score>=60) a[1]++;els...

汇编语言求助:
比较容易啊~RAM中,50H到20H,总共30H个计数 我假设说:伪代码(小细节自己修改)ORG xxxxh MOV R0,#30H ;用于计数 MOV R1,#20H ;用于设定20H到50H的地址,相当于C语言指针 MOV R2,#1000H ;用于片外地址 LOOP1:DEC R0 JE ENDLINE ;为0结束 (如果你们的指令系统有大小比较指令,...

c语言程序这道题怎么做,求助大神
include "stdio.h"#include "math.h"#define pi 3.1415926int main(int argc,char *argv[]){double x,y,t=pi\/2;printf("Input x(R:)...\\nx=");scanf("%lf",&x);if(x<-t)y=5+x*x*x+x*x*x+cos(x)*3;else if(-t<=x && x<t)y=(x-1)\/(x+2)*(x-1)\/(x+2)...

求助一个程序,C语言
include <stdio.h> void main(){ int i,j,n;printf("请输入N:"); scanf("%d",&n);for(i=1; i<=n; i++) { for(j=1; j<i; j++)printf("%3d",j);for(j=0; j<(n-i)*2+1; j++)printf("%3d",i);for(j=i-1; j>=1; j--)printf("%3d",j);printf("\\n"...

祁阳县15122147347: c语言程序求助
答云胆康: 你需要的代码应该是这样: #include<stdio.h>main(){ float x,y,z,ave;/*定义变量*/ printf("请输入三个数:\n"); /*输入提示*/ scanf("%f,%f,%f",&x,&y,&z);/*从键盘输入*/ ave=(x+y+z)/3.0;/*计算*/ ave = (ave*1000+5)/1000; //小数点后第三...

祁阳县15122147347: C语言程序求助
答云胆康: #include <stdio.h> int main (void) { int a = 100; int b = 50; int c; int d; printf ( "请输入c和d的值:" ); scanf ( "%d%d", &c, &d ); if ( a > b ) c = a; else c = b; if ( a < b ) d = a; else d = b; printf ( "a、b、c、d的值分别是:%d %d %d %d\n", a, ...

祁阳县15122147347: C语言编程求助
答云胆康: 这不用if有点麻烦,得用三目运算符“ ? :”. #include<stdio.h> void main() { int a,b,c,max; printf("请输入三个数:"); scanf("%d%d%d",&a,&b,&c); max=a<b?(b<c?c:b):(a<c?c:a); printf("%d\n",max); }

祁阳县15122147347: 求助一个C语言程序
答云胆康: 汗,对于用c的人来说这是送分的吧? 不过我倒是很久没c了……给楼主一点提示吧,不敢保证语法都正确…… 这个题目说白了就是2的63次方嘛.for(n=1;n<64;n++) {n=n*2;} printf("n64=%d",n);

祁阳县15122147347: C语言编程求助 -
答云胆康: #include "stdio.h" void main() { float s,x,m,n; /*s表示汽车行驶的公里数,x表示消耗汽油的升数*/ printf("请输入汽车行驶的公里数,消耗汽油的升数,s,x="); scanf("%f,%f",&s,&x); m=s/x, /*m表示每升汽油可使汽车行驶的公里数*/ n=100*(x/s); /* n表示每百公里消耗汽油的升数*/ printf("%10.2f\n",m); printf("%10.2f",n); }

祁阳县15122147347: C语言程序求助
答云胆康: -2 main() {int m=3,n=4,x; x=-m++;//m++的返回值为m,然后m再++.即x=-3,m=4; x=x+8/++n;//++n的返回值为5,8/5的值为1,则x=-3+1= -2; printf("%d\n",x);// }

祁阳县15122147347: C语言编程求助 -
答云胆康: #include#include int fun2(char *str, char *substr){ int i,j; int cnt; cnt=0; for(i=0,j=0;str[i]!='\0';i++) { if(substr[j]=='\0...

祁阳县15122147347: C语言编程 求助! -
答云胆康: #include<stdio.h> main() { int a,b,c,d; for(a=2;a<=100;a++) { for(b=2;b<a;b++) { for(c=b;c<a&&c>=b;c++) { for(d=c;d<a&&d>=c;d++) if(a*a*a==b*b*b+c*c*c+d*d*d) printf("Cube=%d,Triple=(%d,%d,%d)\n",a,b,c,d); } } } }

祁阳县15122147347: C语言求助 -
答云胆康: 可以这样修改:void fun1(char a[99][20],int c[99],int tmp){ int i=tmp; printf("input name:"); scanf("%s", printf("input num:"); scanf("%d",&c[i]...

祁阳县15122147347: C语言程序求助
答云胆康: 8L正解,嗯,主要是初始化和continue的问题

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网