Advertisement
realever15

程設練習1-7

Oct 17th, 2014
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. //假設使用者友善不會輸入0。
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. int main(void){
  5.     int total=1,temp=1,num,count=0;
  6.     scanf("%d",&num);
  7.     do
  8.     {
  9.      num-=temp;
  10.      temp+=3;
  11.      count++;
  12.     }while(num>=temp);
  13.     printf("  m = %d\nsum = 1",count);
  14.      for(int i=4;i<=temp-3;i+=3)
  15.      {
  16.       if(num==0&&i==-2+3*count)
  17.       break;
  18.       printf("+%d",i);
  19.       total+=i;
  20.      }
  21.     printf(" = %d\n",total);
  22.     system("PAUSE");
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement