32. #include<stdio.h> #include<string.h> #include<stdlib.h> #include<cstring>
int contact(int x,int y)//封装函数 { ?? ? ?? ?return (x > y) ? x : y; } int main() { ?? ?int a = 20; ?? ?int b = 10; ?? ?int max = contact(a,b); ?? ?printf("%d", max);
?? ??? ?return 0; }
33. #include<stdio.h> #include<string.h> #include<stdlib.h> #include<cstring> int ?fun(int n) { ?? ?int j = 0; ?? ?for ( j = 2; j < n; j++) ?? ?{ ?? ??? ?if (n%j==0) ?? ??? ?{ ?? ??? ??? ?return 0; ?? ??? ?} ?? ??? ?return 1; ?? ?} } int main() { ?? ?int i; ?? ?for ( i = 0; i <=200; i++) ?? ?{ ?? ??? ?if (fun(i) == 1) ?? ??? ?{ ?? ??? ??? ?printf("%d是素数\n", i); ?? ??? ?} ?? ?} }
34. #include<stdio.h> #include<string.h> #include<stdlib.h> #include<cstring> int is_leap_year(int n) { ?? ? ?? ?if ((n%4==0)&&(n%100!=0) || (n%400==0))?? ? ?? ??? ?return 1; ?? ?else ?? ??? ?return 0; ?? ? } int main() { ?? ?int year = 1000; ?? ?for ( year = 1000; year < 20001; year++) ?? ?{ ?? ??? ?if (is_leap_year(year)==1) ?? ??? ?{ ?? ??? ??? ?printf("%d是闰年\n", year); ?? ??? ?} ?? ??? ? ?? ? ?? ?} ?? ?return 0; }
35. #include<stdio.h> int main() { ?? ?int num1 = 0; ?? ?int num2 = 0; ?? ?int sum ; ?? ?scanf_s("请输入一个值:%d\n", &num1); ?? ?scanf_s("请输入另一个值%d\n", &num2); ?? ?sum = num1 + num2; ?? ?printf("%d", sum); ?? ?return 0; } ?
|