#include<stdio.h>
#include<stdlib.h>
int main()
{
int a[5] = { 1, 2, 3, 4, 5 };
int b[5] = { 6, 7, 8, 9, 0 };
int i, t;
printf("原数组:\n");
for (i = 0; i < 5; i++){
printf("%d", a[i]);
}
printf("\n");
for (i = 0; i < 5; i++){
printf("%d", b[i]);
}
printf("\n");
for (i = 0; i < 5; i++){
t = a[i];
a[i] = b[i];
b[i] = t;
}
printf("交换后的数组:\n");
for (i = 0; i < 5; i++){
printf("%d", a[i]);
}
printf("\n");
for (i = 0; i < 5; i++){
printf("%d", b[i]);
}
printf("\n");
system("pause");
return 0;
}
计算1/1-1/2······+1/99-1/100的值:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int f = 1,i;
double sum = 0;
for (i = 1; i <= 100;i++){
//sum = sum + f / i;
sum += 1.0 * f / i;
f *= -1;
}
printf("%lf\n", sum);
system("pause");
return 0;
}
1 到 100 的所有整数中出现多少次数字9:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,j=0;
for (i = 1; i <= 100; i++)
{
if (i % 10 == 9){
j++;
}
else if (i / 10 == 9){
j++;
}
}
printf("出现9的次数:\n");
printf("%d\n", j);
system("pause");
return 0;
}
交换两个数组的内容:#include&amp;amp;lt;stdio.h&amp;amp;gt;#include&amp;amp;lt;stdlib.h&amp;amp;gt;int main(){ int a[5] = { 1, 2, 3, 4, 5 }; int b[5] = { 6, 7, 8, 9, 0 }; int i, t; printf(&amp;quot;原数组:\n&amp;quot;); for (i