今天又冷了起来呢,我穿上了外套去敲代码了。感觉它逐渐变得神奇了起来!真好!
将数组A和数组B中的内容进行交换
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int i = 0;
int t = 0;
int arr1[3], arr2[3];
printf("输入两个数组\n");
scanf("%d%d", &arr1[i], &arr2[i]);
t = arr1[i];
arr1[i] = arr2[i];
arr2[i] = t;
printf("数组交换后为:\n%d,%d\n", arr1[i], arr2[i]);
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()
{
float i = 0;
int a = 1;
float sum = 0;
for (i = 1; i <= 100; i++){
sum = sum + a / i;
a = a*(-1);
}
printf("%f\n", sum);
system("pause");
}
编写程序数一下 1到 100 的所有整数中出现多少次数字9。
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a = 1;
int sum = 0;
for (a = 1; a <= 100; a=a+1){
if (a % 10 == 0){
sum += 1;
}
if (a/10==9){
sum += 1;
}
}
printf("出现9的次数为%d\n", sum);
system("pause");
return 0;
}