
给定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("</p><p> %d",((2*i)-1)); i++;
}
}如果我们运行上面的程序,它将生成以下输出
1 3 5 7 9
以上就是打印n个数字,使它们的和是一个完全平方数的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号