"c语言练习题答案:谭浩强C语言习题详细解答,12章全覆盖"

需积分: 0 1 下载量 173 浏览量 更新于2024-03-13 收藏 574KB DOC 举报
&x,&y,&z);max=(a>b)?a:b;max=(max>c)?max:c;printf("最大者是%d\n",max);}这个程序实现的功能是输入三个数a、b、c,然后找出其中最大的数并输出。程序首先定义了四个整型变量a、b、c、max,然后通过printf函数提示用户输入三个数,接着通过scanf函数分别将用户输入的三个数赋值给a、b、c。接着利用三目运算符(条件?为真时的值:为假时的值)来进行比较,如果a>b,则max=a,否则max=b;然后再利用三目运算符来比较max和c,找出其中最大的数赋值给max,最后通过printf函数输出max的值,即为最大者。" "The C language exercise answers; Tan Haoqiang's C language exercises and answers, a total of 12 chapters. Very detailed, please check.; 1.6 Write a program, input three values a, b, c, and output the largest value. Solution: main () {int a, b, c, max; printf ("Please enter three numbers a, b, c: \n"); scanf ("%d,%d,%d", &x, &y, &z); max = (a> b)? a: b; max = (max> c)? max: c; printf ("The largest one is %d\n", max);} This program is to input three numbers a, b, c, and then find the largest number and output it. The program first defines four integer variables a, b, c, max, then prompts the user to enter three numbers through the printf function, and then assigns the three numbers entered by the user to a, b, and c through the scanf function. Then use the ternary operator (condition? Value when true: Value when false) to compare, if a> b, then max = a, otherwise max = b; and then use the ternary operator to compare max and c, find the largest number and assign it to max, and finally use the printf function to output the value of max, which is the largest one."