#include<stdio.h>
#include<stdlib.h>
int main(){
int a[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int a1[10] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
int i;
for (i = 0; i < 10; i++){
int temp = a[i];
a[i] = a1[i];
a1[i] = temp;
}
for (i = 0; i < 10; i++){
printf("%d ", a[i]);
}
printf("\n");
for (i = 0; i < 10; i++){
printf("%d ", a1[i]);
}
printf("\n");
system("pause");
return 0;
}
计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值。
#include<stdio.h>
#include<stdlib.h>
int main(){
double sum = 0.0;
double t = 1.0;
for (int i = 1; i <= 100; i++){
sum = sum + 1 / (t*i);
t = -t;
}
printf("%f\n", sum);
system("pause");
return 0;
}
编写程序数一下 1到 100 的所有整数中出现多少次数字9。
#include<stdio.h>
#include<stdlib.h>
int main(){
int a;
int count = 0;
for (a = 1; a <= 100; a++){
if (a % 10 == 9){
count++;
}
if (a / 10 == 9){
count++;
}
}
printf("%d\n", count);
system("pause");
return 0;
}