1、C 程序设计教程书后第一章习题详解1.求出 10 个数中的最大数:/*用一个数组来存放 10 个数*/#includemain()int a10,i,max;printf(“Please enter 10 numbers:n“);for(i=0;imax)max=ai;printf(“The max number is %d“,max);getch();/*用一个变量来存放 10 个数*/#includemain()int i,m,max;printf(“Please enter 10 numbers:n“);scanf(“%d“,max=m;for(i=2;imax)max=m;printf
2、(“The max number is %d“,max);getch();2.求两个正整数的最大公约数:/*逐个尝试法求两个正整数的最大公约数*/#includemain()int m,n,i,t;printf(“Please enter two positive integral numbers:n“);scanf(“%d %d“,for(i=1;imain()int m,n,r;printf(“Please enter two positive integral numbers:n“);scanf(“%d %d“,r=m%n;while(r!=0)m=n;n=r;r=m%n;printf(
3、“The highest common divissor of the two numbers is %d“,n);getch();/*辗转相减法求两个正整数的最大公约数*/#includemain()int m,n,r,t;printf(“Please enter two positive integral numbers:n“);scanf(“%d %d“,if(mmain()int m,n,i;printf(“Please enter the poseble range (m to n):n“);scanf(“%d %d“,printf(“The posible number is:n“
4、);for(i=m;imain()int a,b,t;printf(“Please enter two numbers:n“);scanf(“%d %d“,t=a;a=b;b=t;printf(“The changed two numbers are:n%d %d“,a,b);getch();/*交换时不引进变量*/#includemain()int a,b;printf(“Please enter two numbers:n“);scanf(“%d %d“,a=b-a;b=b-a;a=a+b;printf(“The changed two numbers are:n%d %d“,a,b);g
5、etch();/*交换时用位运算*/#includemain()int a,b;printf(“Please enter two numbers:n“);scanf(“%d %d“,a=ab;b=ba;a=ab;printf(“The changed two numbers are:n%d %d“,a,b);getch();4.将从键盘上输入的任一字符分别以字符和十进制数两种方式输出:#includemain()char c;printf(“Please enter any char:n“);c=getchar();printf(“The form of char is %cnThe form of digit is %d“,c,c);getch();