c語言學習5

來源:互聯網
上載者:User

標籤:define   oat   ota   結束   studio   mount   c語言學習   int   style   

 
break 和 continue之間的區別:
在1000人中,募捐100000元,當達到10萬元後結束   break 跳出當前迴圈,即  是終止迴圈,continue結束本次迴圈,不終止迴圈
#include <studio.h>
#define SUM 100000
int main(){
   float amount,aver,total;
   int i;
  for (i=1,total=0;i<=1000;i++){
        printf("please enter amount");
        scanf("%f",&amount);
        total=total+amount;
        if (total>=SUM) break;
 
}
aver=total/i;
printf("num=%d\naver=%10.2f\n",i,aver);
return 0;
 
}
 
 
100  ```200之間能被3整除的數
#include <studio.h>
int main(){
   int n;
  for (n=100;n<=200;n++){
        if (n%3==0){
             ontinue;
        printf("%d",n);
}
 
printf("\n");
return 0
}
}
 
 
#include <studio.h>
int main(){
  int i,j,n=0;
  for(i=1;i<=4;i++){                   #這裡是1到4之間迴圈  
       for(j=1;j<=5;j++,n++)        #控制在輸出5個資料之後換行
            if(n%5==0)  printf("\n");
            printf("%d\t",i*j);
 
             
 
}
printf("\n");
return  0;
 
}
 
1  2  3  4    5    #數字是一行一行列印出來的 ,迴圈出來
2  4  6  8    10
3  6  9  12  15
4  8  12  16  20    
 
 
 
#include <studio.h>
int main(){
  int i,j,n=0;
  for(i=1;i<=4;i++){                   #這裡是1到4之間迴圈  
       for(j=1;j<=5;j++,n++)        #控制在輸出5個資料之後換行
            if(n%5==0)  printf("\n");
            if(i==3&& j==1) break;
            printf("%d\t",i*j);
 
             
 
}
printf("\n");
return  0;
 
}
 
1 2 3 4 5
2 4 6 8 10
 
4 8 12 16 20
 
 
 
 
#include <studio.h>
int main(){
  int i,j,n=0;
  for(i=1;i<=4;i++){                   #這裡是1到4之間迴圈  
       for(j=1;j<=5;j++,n++)        #控制在輸出5個資料之後換行
            if(n%5==0)  printf("\n");
            if(i==3&& j==1) continue
            printf("%d\t",i*j);
}
printf("\n");
return  0;
 
}
 
 
1 2 3 4 5
2 4 6 8 10
6 9 12 15
4 8 12 16 20

c語言學習5

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.