1. int Max_Int(int a,int b) { return a > b ? a : b; } int main() { int a = 0, b = 0, c = 0; scanf_s("%d%d%d", &a, &b, &c); int max = 0; max = Max_Int(Max_Int(a, b), c);//函数的递归,先将a,b的最大值比较出来,把值给一个临时的变量,再将变量和c进行比较 printf("max=%dn", max); return 0; } 2. int main() { int a = 0, b = 0, c = 0; scanf_s("%d%d%d", &a, &b, &c); int max = 0; max = a > b ? a : b; max = max > c ? max : c; printf("max=%dn", max); return 0; } 3. int main() { int a = 0, b = 0, c = 0; scanf_s("%d%d%d", &a, &b, &c); int max = 0; if (a > b && a > c) { max = a; } else if (b > a && b > c) { max = b; } else max = c; printf("max=%dn", max); return 0; }
在键盘上输入三个数求他们中间的那个数
void swap(int* a, int* b) { int temp = 0;//int *temp=NULL;只是一个空指针,没有地址,所以指针指向随机值,不能使用空指针在这 temp = *a; *a = *b; *b = temp; } int Mid_Int(int x, int y, int z) { if (x > y) { swap(&x, &y); } if (y > z) { swap(&y, &z); } if (x > y) { swap(&x, &y); } return y; } int main() { int a = 0, b = 0, c = 0; scanf_s("%d%d%d", &a, &b, &c); int mid = 0; mid = Mid_Int(a, b, c); printf("mid=%dn", mid); return 0; } int Mid_Int(int a, int b, int c) { int temp = 0; if (a > b) { temp = a; a = b; b = temp; } if (b > c) { temp = c; c = b; b = temp; } if (a > b) { temp = a; a=b; b = temp; } return b; } int main() { int a = 0, b = 0, c = 0; scanf_s("%d%d%d", &a, &b, &c); int mid = 0; mid = Mid_Int(a, b, c); printf("mid=%dn", mid); return 0; }
在键盘上输入一行或多行字符串,统计他们其中数字,大小写字母,控制字符,以及其他字符
int main() { char ch = ''; int consum = 0, digsum = 0, capsum = 0, smasum = 0, othsum = 0; while (ch = getchar(), ch != 'n') { if (iscntrl(ch)) { consum += 1; } else if (isdigit(ch)) { digsum += 1; } else if (isupper(ch)) { capsum += 1; } else if(islower(ch)) { smasum += 1; } else { othsum += 1; } } printf("consum: %d n", consum); printf("digsum: %d n", digsum); printf("capsum: %d n", capsum); printf("smasum: %d n", smasum); printf("othsum: %d n", othsum); return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)