欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

《第七天:刚开始学习C语言》

最编程 2024-01-06 20:20:55
...

////写一个代码打印1-100之间所有3的倍数的数字

//#include<stdio.h>

//int main()

//{

// int i = 1;

// for (i = 1; i >= 1 && i <= 100; i++)

// {

//  if (i % 3 == 0)

//  {

//   printf("%d\n", i);

//  }

// }

// return 0;

//}

//写代码将三个整数数按从大到小输出

//#define _CRT_SECURE_NO_WARNINGS 1

//#include<stdio.h>

//int main()

//{

// int a, b, c;

// scanf("%d%d%d",&a,&b,&c);

// if (a > b && a > c && b > c)

// {

//  printf("%d %d %d\n",a,b,c);

// }

// if (a > b && a > c && c>b)

// {

//  printf("%d %d %d\n", a, c,b);

// }

// if (b>a && b > c && a > c)

// {

//  printf("%d %d %d\n", b,a, c);

// }

// if (b > a && b > c&&c>a)

// {

//  printf("%d %d %d\n", b,c,a);

// }

// if (c > a && c>b && a>b)

// {

//  printf("%d %d %d\n",c,a,b);

// }

// if (c > a && c > b&&b > a)

// {

//  printf("%d %d %d\n", c,b,a);

// }

// return 0;

//}

////针对每组输入数据,输出占一行,如果能构成三角形,等边三角形则输出“Equilateral triangle!”,

//// 等腰三角形则输出“Isosceles triangle!”,其余的三角形则输出“Ordinary triangle!”,反之输出“Not a triangle!”。

//#define _CRT_SECURE_NO_WARNINGS 1

//#include <stdio.h>

//int main()

//{

//    int a = 1, b = 1, c = 1;

//

//    while (scanf("%d %d %d", &a, &b, &c) != EOF)

//    {

//        if (a + b > c && a + c > b && b + c > a)

//        {

//            if (a == b && b == c)

//            {

//                printf("Equilateral triangle!\n");

//            }

//            else if (a == b || b == c || a == c)

//            {

//                printf("Isosceles triangle!\n");

//            }

//            else

//            {

//                printf("Ordinary triangle!\n");

//            }

//        }

//        else

//        {

//            printf("Not a triangle!\n");

//        }

//    }

//    return 0;

//}

////计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值,打印出结果

//#include <stdio.h>

//int main()

//{

//    double sum = 0.0;

//    for (int i = 1; i <= 100; i++)

//    {

//        sum += 1.0 / i;

//    }

//    printf("The sum of 1 + 1/2 + 1/3 + ... + 1/100 is: %f", sum);

//    return 0;

//}

////编写程序数一下 1到 100 的所有整数中出现多少个数字9

//#include <stdio.h>

//int main()

//{

//    int i = 0;

//    for (int i = 1; i <= 100; i++)  

//    {

//        if (i % 10 == 9)

//            printf("%d\n", i);

//        if(i/10==9)

//            printf("%d\n", i);

//    }

//    return 0;

//}

////打印1000年到2000年之间的闰年

//#include <stdio.h>

//int main()

//{

//    int year;

//    printf("Leap years between 1000 and 2000:\n");

//    for (year = 1000; year <= 2000; year++)  

//    {

//        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))

//        {

//            printf("%d\n", year);

//        }

//    }

//    return 0;

//}

////求10 个整数中最大值

//#define _CRT_SECURE_NO_WARNINGS 1

//#include  <stdio.h>

//int  main() {

//    int  arr[10];

//    int  i, max = 0;

//    printf("请输入十个整数:\n");

//    for (i = 0; i < 10; i++) {

//        scanf("%d", &arr[i]);

//        if (arr[i] > max) {

//            max = arr[i];

//        }

//    }

//    printf("其中最大的数为:%d\n", max);

//    return  0;

//}

// //调试,寻找bug,并解决

//#define _CRT_SECURE_NO_WARNINGS 1

//#include <stdio.h>

//int main()

//{

// int i = 0;

// int sum = 0;//保存最终结果

// int n = 0;

// int ret = 1;//保存n的阶乘

// scanf("%d", &n);

//

// for (i = 1; i <= n; i++)

// {

//  int j = 0;

//  ret = 1;//解决办法,给ret初始化

//  for (j = 1; j <= i; j++)//计算3!的时候出错了

//  {

//   ret *= j;//原因在于,每次循环,ret的值并没有恢复初始值

//  }

//  sum += ret;

// }

// printf("%d\n", sum);

// return 0;

//}