17-11-10

作业一:累加求和

#include
int main()
{
    int i=1;
    int sum=0;
    do
    {
        sum=sum+i;
        i++;
    }while(i<=100);
    printf("1+...+%d=%d\n",i-1,sum);
    return 0;
}

作业二:累加求和(二)

   #include 
   int main()
{
       int i = 1;
       int sum = 0;
       do{
           if(i%2 != 0){
           sum += i;
       }
           ++i;
      }while(i != 101);
      printf("总和为:%d\n",sum);
      return 0;
}

作业三:累加求和(三)

   #include 
   int main()
{
       int i = 1;
       int sum = 0;
       do{ 
           if(i%2 == 0){
           sum += i; 
       }   
           ++i;
      }while(i != 101);
      printf("总和为:%d\n",sum);
      return 0;
  }

作业四:输入求和

   #include 
   int main()
{
       int sum = 0,count = 0,bool_cin = 1;
       while(bool_cin){
           int num = 0;
           printf("请输入一个整数\n");
           scanf("%d",&num);
           sum += num;
           ++count;
          printf("是否继续?yes->1 no->0\n");
          scanf("%d",&bool_cin);
      }
      double ave = (double)sum/count;
      printf("和为%d,平均值为%.2g\n",sum,ave);
      return 0;
  }

作业五:看结果写程序

   #include 
   int main()
{
       int num1 = 0,num2 = 0,sum = 0;
       printf("请输入两个整数\n");
       scanf("%d%d",&num1,&num2);
       if(num1 > num2){
           num1 += num2;
           num2 = num1-num2;
           num1 -= num2;
      }
      int i = 0;
      for(i = num1;i <= num2;i++){
          sum += i;
      }
      printf("大于等于%d小于等于%d的整数之和为%d\n",num1,num2,sum);
      return 0;
  }

你可能感兴趣的:(17-11-10)