1. 将数组A中的内容和数组B中的内容进行交换。数组一样大)2. 计算1/1-1/2+1/3-1/4+1/5 ⋯⋯ + 1/99 - 1/100 的值。3. 编写程序数一下 1到 100 的9的个数。

#include<stdio.h>
#include<windows.h>
#include<string.h>
#include<math.h>
#pragma warning(disable:4996)
void showarray(int a[], int num)
{
    int i = 0;
    for (; i < num; i++)
    {
        printf("%d", a[i]);
    }
    printf("\n");
}
double Result(int top)
{
    int i = 1;
    int flag = 1;
    double re= 0.0;
    for (; i <= top; i++)
    {
        re += (1.0 / (flag*i));
        flag = -flag;
    }
    printf("1/1-1/2+1/3-1/4+1/5 ⋯⋯ + 1/99 - 1/100 =%f\n", re);
    return re;

}
int count()
{
    int _count = 0;
    int i = 0;
    for (; i < 100; i++)
    {
        if (i < 10 && i == 9)
            _count++;
        else  
        {
            if (i % 10 == 9)
                _count++;
            if(i / 10 == 9)
                _count++;
        }
    }
    printf("1-100 the number of 9%d ,", _count);
    return _count;
}
int main()
{
    //1. 将数组A中的内容和数组B中的内容进行交换。(数组一样大)
    int i = 0;
    int a[] = { 1,5,2,6,9 };
    int b[] = { 3,7,8,4,5 };
    int num = sizeof(a) / sizeof(a[0]);
    printf("交换前:\n");
    showarray(a, num);
    showarray(b, num);
    for (; i < num; i++)
    {
        a[i] ^= b[i];
        b[i] ^= a[i];
        a[i] ^= b[i];
    }
    printf("交换后:\n");
    showarray(a, num);
    showarray(b, num);
    //2. 计算1/1-1/2+1/3-1/4+1/5 ⋯⋯ + 1/99 - 1/100 的值。
    Result(100);
    //3. 编写程序数一下 1到 100 的所有整数中出现多少个数字9。
    count();
    system("pause");
}

发布了35 篇原创文章 · 获赞 7 · 访问量 3203

猜你喜欢

转载自blog.csdn.net/weixin_44358097/article/details/89974278