c的小程序回顾
#include<stdio.h>
#include<string.h>
//求1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值。
void solve()
{
double sum=0;
for (int m = 1; m <= 100; m++)
{
if (m%2==0)
sum -= 1 / (double)m;
else
sum += 1 / (double)m;
}
printf("%f", sum);
}
//将数组A中的内容和数组B中的内容进行交换。(数组一样大)
void swap1(int *a, int *b)
{
*a = *a + *b;
*b = *a - *b;
*a = *a - *b;
}
void swap_arr(int *a, int *b,int n)
{
for (int i = 0; i < n; i++)
swap1(a + i, b + i);
}
//编写程序数一下 1到 100 的所有整数中出现多少次数字9
void num_9()
{
int count=0,j,k;
for (int i = 1; i <= 100; i++)
{
j = i % 10;
if (j == 9 )
count++;
k = i / 10 % 10;
if (k == 9)
count++;
}
printf("%d", count);
}
int main()
{
int a[10] = { 1, 2, 3, 4, 5 };
int b[10] = { 6, 7, 8, 9, 10 };
swap_arr(a, b, 5);
for (int i = 0; i < 5; i++)
printf("%d ", a[i]);
printf("\n");
for (int i = 0; i < 5; i++)
printf("%d ", b[i]);
//solve();
num_9();
return 0;
}