再接再厉
1.将数组A中的内容和数组B中的内容进行交换。(数组一样大)
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char str1[5];
char str2[5];
char str3[5];
puts("请输入str1的字符:\n");
gets(str1);
puts("请输入str2的字符:\n");
gets(str2);
strcpy(str3, str1);
strcpy(str1, str2);
strcpy(str2, str3);
puts("互换后str1数组为:\n");
puts(str1);
printf("\n");
puts("互换后str2数组为:\n");
puts(str2);
printf("\n");
return 0;
system("pause");
}
2.计算1/1-1/2+1/3-1/4+1/5…….+1/99-1/100的值。
#include <stdio.h>
#include<stdlib.h>
int main()
{
int i=1;
double sum = 0;
while (i <= 100)
{
if (i % 2 == 1)
sum = sum + 1.0 / i;
else
sum = sum - 1.0 / i;
i++;
}
printf("%4f\n", sum);
system("pause");
}
3.编写程序数一下1到100的所有整数中出现多少次数字9
#include<stdio.h>
int main()
{
int a, b;
int i;
int count = 0;
for (i = 1; i <= 100; i++)
{
a = i / 10;
b = i / 10;
if (a == 9)
count++;
if (b == 9)
count++;
}
printf("%d\n", count);
system(“pause”);
}