輸出 n 個數字,使它們的和為一個完全平方數


程式已給定 n 個數字,必須找到這 n 個數字,使它們的和為一個完全平方數

Input : 5
Output : 1 3 5 7 9
1+3+5+7+9=25 i.e (5)^2

演算法

START
   Step 1 : Declare a Macro for size let’s say of 5 and i to 1
   Step 2: loop While till i<=SIZE
      Step 2.1 -> printing (2*i)-1 Step
      Step 2.2 -> incrementing i with 1 Step
   Step3-> End loop While
STOP

示例

#include <stdio.h>
# define SIZE 5
int main() {
   int i=1;
   while(i<=SIZE) {
      printf("
%d",((2*i)-1)); i++;    } }

輸出

如果我們執行以上程式,它將生成以下輸出

1
3
5
7
9

更新於: 2019-Jul-30

140 次瀏覽

啟動你的 職業生涯

完成該課程,獲得認證

開始
廣告