6.  寫一個程式,它在螢幕上要印成這樣子

Smile! Smile! Smile!

Smile! Smile!

Smile!

這程式只能宣稱一個印出Smile!的函數,其他部分需由這函數來完成

 

程式碼如下

// ch2_wr6.cpp : Defines the entry point for the console application.

//

 

#include "stdafx.h"

#include <stdio.h>                   //引入stdio.h

void prt_smile_txt(void);       //宣稱一個prt_jolly_txt函數

int main(int argc, char* argv[]) {

     int i,j;                        //宣告變數my_year和變數cal_value

 

     for(i=1;i<=3;i++){              //使用迴圈,把assigni變數當作起始值,當i小於或等於時停止迴圈,每次迴圈執行完畢i就加

           for(j=i;j<=3;j++){         //使用迴圈,把i變數值assignj變數當作起始值,當j小於或等於時停止迴圈,每次迴圈執行完畢j就加

                prt_smile_txt();     //呼叫prt_smile_txt函數

           }

           printf("\n");              //印出換行字串

     }

 

     return 0;                       //函數結束,傳回整數並跳回原本呼叫的地方

}

 

void prt_smile_txt(void){       //prt_smile_txtFunction head,回傳值設為沒有回傳值,參數設為沒有參數

 

     printf("Smile!");               //印出字串

}

arrow
arrow
    全站熱搜

    Johnny 鋼鍊 發表在 痞客邦 留言(0) 人氣()