这个程序实现的是交换两个数组的值。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main()
{
int arr1[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, };
int arr2[10] = { 9, 8, 7, 6, 5, 4, 3, 3, 2, 1, };
int len1 = sizeof(arr1) / sizeof(arr1[0]);
int len2 = sizeof(arr2) / sizeof(arr2[0]);
int i = 0;
int temp = 0;
for (i = 0; i <=len1 - 1; ++i)
{
temp = arr1[i];
arr1[i] = arr2[i];
arr2[i] = temp;
printf("%d\n,%d\n", arr1[i], arr2[i]);
}
system("pause");
return 0;
}
这段代码实现的是求1/1-1/2+1/3-1/4+....-1/99+1/100的值。
int i = 0;
double sum = 0.0;
int flag = 1;
for (i = 1; i <101; ++i)
{
sum = sum + flag*1.0 / i;
flag = -flag;
}
printf("%f", sum);
system("pause");
return 0;
}
这段代码是找出1-100之间各位为九的数字
int i = 0;
int j = 0;
int count = 0;
for (i = 9; i < 100; ++i)
{
if (i % 10 == 9 || i / 10 == 9)
{
count++;
printf("%d\n", i);
}
}
printf("count==%d\n", count);
system("pause");
return 0;
}