Advertisement
kk258966

4/9 C++ 練習二

Apr 9th, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(void)
  4. {
  5.  int i;
  6.  
  7.  for(i=8;i<=15;i++)
  8.  {
  9.                    printf("%d\n",i);
  10.  }
  11.        
  12.  
  13. printf("============================\n");
  14.  
  15. int num=0,count=0;
  16. i=8;
  17.  
  18. while(i<=15)
  19. {
  20. num = num + i;  
  21. count++;    
  22. i++;    
  23.  
  24. }
  25. printf("num=%d\n",num);
  26. printf("總共%d個數字\n",count);
  27. printf("平均為%f",(float)num/count);
  28. printf("\n============================\n");
  29.  
  30.     system("pause");
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement