gets(string); while(string[i]!=\'\\0\') { if(string[i]>=\'A\'&&string[i]<=\'Z\'||string[i]>=\'a\'&&string[i]<=\'z\') letter++; else if(string[i]==\' \') spa++; else if(string[i]>=\'0\'&&string[i]<=\'9\') dig++; else other++; i++; } printf(字符:%d\\n数字:%d\\n空格:%d\\n其他字符:%d\\n}
9.10.1
#include
Int a,b; Int c=0;
Printf(Scanf(C=Max(a,b);
printf(%d\\nReturn 0; }
Int Max(int x,int y) {
Int x,y;这里没必要重新定义了 Int max=0;
max=(x>y)?x:y; Renturn (max); }
9.10.2
#include
Double Average(double Score[]); Int i=0; Void main() {
Double Daverage; Double Dstudent[10]; For(;i<10;i++) {
Scanf(}
Daverage=Average(Dstudent); Printf(平均成绩为:\\n}
Double Average(double Score[]) {
double sum; Double A=0; For(;i<10,i++) {int i=0;
sum+=Score[i]; }
A=sun/10; Return A; }
全局变量 在定义函数的时候不起作用
10.8.1
#include
Int i=0; int Ar[];
Ar[]=sort(Ar,5); For(;i<5;i++)
Printf(}
Void sort(int *p,int n) {
Int j=0,iTemp; For(;j *(p+j)=iTemp; *(p+n-j)=*(p+j); iTemp=*(p+n-j); } 自己修改过的程序如下 #include void sort(int *p,int n) { int m,iTemp,j=0; m=n/2; for(;j } } printf(排序后的数组为:\\nfor(j=0;j 注意了 这里的j=0不能省略,因为j在执行完循环后已经为n/2-1,所以省去之后输出会出错,费尽周折才检查出 10.8.2 #include int *p,*q;要用char Char str1[30],str2[要写大小]; Printf(gets(str1,str2); P=str1; While(*p!=′\\0′) P++; For(q=str2;*p!=′\\0;′) *P++=*q++; *p=′\\0′; Printf(} 修改后的程序注重细节 #include 10.8.3 #include Int *p,*q; Char str1[],str2[]; P=str1,q=str2; While(*q!=0)这是什么意思? P++; Q++;这呢? *p=’\\0’; Printf(“the str1 is:%s\\n”,str1); } 错误百出 修改后 #include 答案就不用看了 11.10.1 #include struct person { char name[20]; int count; }; int main() { struct person Person[3]={ { char name[10]; int i,j,t,max; printf(欢迎来到投票系统-----\\n for(i=0;i<10;i++) { printf(请输入你所要投的人的姓名:\\n scanf( for(j=0;j<3;j++) { if(strcmp(Person[j].name,name)==0) { Person[j].count++; } } } for(i=0;i<3;i++) { printf( } max=Person[0].count; for(i=0;i<3;i++) { if(max return 0; } 输出得票最多的候选人名字 改为如下 Max=Person[0].count; If(max>=Person[1].count && max>=Person[2].count) { Printf();} Else if() Else 或者用while While(max>=Person[1].count) {if() {} Else{} ?? 11.10.2 参照答案 #include union Category { int iClass; /*班级*/ char position[20]; /*职务*/ }; struct Person { char cJob; /*职业*/ char cName[20]; /*姓名*/ int iNumber; /*编号*/ char cSex; union Category Position; }; void DisplayStudent(struct Person person) { printf( printf( printf( printf( printf(} void DisplayTeacher(struct Person person) { printf( printf( printf( printf( printf(} int main() { struct Person person[100]; person[0].cJob=\'S\'; person[0].cName=/不能用赋值语句将一个字符串常量或字符数直接赋值给一个字符数组 改为 strcpy(person[0].cName, person[0].cSex=\'G\'; person[0].iNumber=\'1\'; person[0].Position.iClass=1; person[1].cJob=\'T\'; strcpy(person[1].cName, person[1].cSex=\'G\'; person[1].iNumber=1010; strcpy(person[1].Position.position, DisplayStudent(person[0]); DisplayTeacher(person[1]); } 12.6.1 #include Int a,b,c=0; Puts(“please enter two number:”); Scanf(“%d,%d”,&a,&b); C=a&b; Printf(“”); ?? 12.6.2略 12.6.3 #include Int a,n,Value=0; Puts(“please enter the number of a:”); Scanf(“%d”,&a); Puts(“please enter the value of n:”); Scanf(“%d”,&n); Value=(a>>(32-n))|(a< Printf(“循环左移结果为:%d\\n”,Value); Value=(a<<(32-n))|(a>>n); Printf(“循环右移结果为:%d\\n”,Value); Return 0; }
百度搜索“70edu”或“70教育网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,70教育网,提供经典综合文库C习题(2)在线全文阅读。
相关推荐: