脚本宝典收集整理的这篇文章主要介绍了第1章(第四版)编程习题,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
P15
例1:输出This is a C program
#include<stdio.h> int main() { printf("This is a C programn"); return 0; }
例2:求两个整数之和
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> int main() { int a = 0; int b = 0; int sum = 0; scanf("%d%d",&a,&b); sum = a + b; printf("sum= %dn",sum); return 0; }
例3:求两个整数中最大值
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> int main() { int a = 0; int b = 0; int max = 0; scanf("%d%d", &a, &b); max=(a>b?a:b); printf("max= %dn", max); return 0; }
输出信息
**************
Very good!
**************
#include<stdio.h> int main() { printf("**************n"); printf("Very good!n"); printf("**************n"); return 0; }
输入a,b,c,输出最大值
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> int main() { int a, b, c, max; printf("please input a,b,c:n"); scanf("%d,%d,%d",&a,&b,&c); max = a; if (max < b) max = b; if (max < c) max = c; printf("The largest number is %dn", max); return 0; }
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> int main() { int max(int x, int y, int z); int a, b, c, d; scanf("%d %d %d", &a, &b, &c); d = max(a, b, c); printf("max = % dn",d); return 0; } int max(int x, int y, int z) { int g; if (x > y && x > z) g = x; else if (y > x && y > z) g = y; else if (z > x && z > y) g = z; return (g); }
以上是脚本宝典为你收集整理的第1章(第四版)编程习题全部内容,希望文章能够帮你解决第1章(第四版)编程习题所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。