27. #include<stdio.h> #include<string.h> #include<stdlib.h> #include<Windows.h> #include<math.h>
int?? ?main() {
?? ?int?? ? i = 0; ?? ?double sum = 0; ?? ?int flag = 1; ?? ?for ( i = 1; i <=100; i++) ?? ?{ ?? ??? ?sum =flag* 1.0 / i; ?? ??? ?flag = -flag; ?? ?} ?? ?printf("%lf", sum); ?? ?return 0; }
28. #include<stdio.h> #include<string.h> #include<stdlib.h> #include<Windows.h> #include<math.h>
int?? ?main() {
?? ?int?? ?arr[] = { -1,2,3,4,-5,6,7,8,9,10 }; ?? ?int max = arr[0]; ?? ?int i = 0; ?? ?int sz = sizeof(arr) / sizeof(arr[0]); ?? ?for ( i = 0; i <sz; i++) ?? ?{ ?? ??? ?if (arr[i]>max) ?? ??? ?{ ?? ??? ??? ?max = arr[i]; ?? ??? ?} ?? ?} ?? ?printf("最大值为%d", max); ?? ?return 0; }
29. #include<stdio.h> #include<string.h> #include<stdlib.h> #include<Windows.h> #include<math.h>
int?? ?main() { ?? ?int i = 0; ?? ?int j = 0; ?? ?for ( i = 1; i <10; i++) ?? ?{ ?? ??? ?for (j = 1; j <= i; j++) ?? ??? ?{ ?? ??? ??? ?printf("%d*%d=%-2d ", i, j, i * j);;//-2d 向左靠齐,不够补空格 ?; 2d向右靠齐 ?? ??? ?} ?? ??? ?printf("\n"); ?? ?} ?? ?return 0; }
|