C语言远征第三天
1.将数组A中的内容和数组B中的内容进行交换。(数组一样大)
char arr1[] = {"welcome to bit#####"};
char arr2[] = {"you are hardworking"};
char arr3[20];
for (int i = 0; i < strlen(arr1); i++)
{
arr3[i] = arr1[i];
arr1[i] = arr2[i];
arr2[i] = arr3[i];
}
printf("arr1 = %s\n arr2 = %s\n", arr1, arr2);
2. 计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值。
float sum = 0,a = -1;
int i;
for (i = 1; i <= 100; i++)
{
sum = sum - (a / i);
a = a * (-1);
}
printf("%f\n", sum);
3.编写程序数一下 1到 100 的所有整数中出现多少次数字9
int count = 0,i = 0;
for (i = 1; i < 101; i++)
{
if (((i - 9) % 10 == 0) || ((i / 10) == 9))
{
count++;
if (((i - 9) % 10 == 0) && ((i / 10) == 9))
{
count++;
}
}
}
printf("%d\n", count);
坚持就是胜利!!!