編寫一個用 C++ 語言編寫的國際婦女節程式


在全球 10 月 7 日慶祝的婦女節被刻畫為一段 c++ 程式設計程式碼,如下所示;

示例

#include <iostream>
using namespace std;
int main(){
   // Initializing size of
   // design
   int n = 5;
   // Loop to print Circle
   // (Upper part of design)
   // Outer loop to
   // control height of
   // design
   for (int i = 0; i <= 2 * n; i++) {
      // Inner loop to control
      // width
      if (i == n)
      cout << " "<< "7 Oct";
      for (int j = 0; j <= 2 * n; j++) {
         // computing distance of
         // each point from center
         float center_dist = sqrt((i - n) * (i - n) + (j - n) * (j - n));
         if (center_dist > n - 0.5 && center_dist < n + 0.5)
            cout << "#";
         else
            cout << " ";
      }
      // Printing HappY Women's DaY
      if (i == n)
         cout << " "<< "Happy Women's Day";
      cout << endl;
   }
   // Loop to print lower part
   // Outer loop to control
   // height
   for (int i = 0; i <= n; i++) {
      // Positioning pattern
      // Loop for Printing
      // horizontal line
      if (i == (n / 2) + 1) {
         for (int j = 0; j <= 2 * n; j++)
            if (j >= (n - n / 2) && j <= (n + n / 2))
               cout << "*";
            else
               cout << " ";
      }
      else {
         for (int j = 0; j <= 2 * n; j++) {
            if (j == n)
               cout << "*";
            else
               cout << " ";
         }
      }
      cout << endl;
   }
}

輸出

在編譯上述程式碼後,程式生成如下輸出;

更新於: 29-Nov-2019

369 次瀏覽

開啟您的 職業生涯

完成課程後獲得認證

開始學習
廣告
© . All rights reserved.