- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print n numbers such that their sum is a perfect square
Given with n numbers program must find those n number whose sum is a perfect square
Input : 5 Output : 1 3 5 7 9 1+3+5+7+9=25 i.e (5)^2
Algorithm
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
Example
#include <stdio.h> # define SIZE 5 int main() { int i=1; while(i<=SIZE) { printf("
%d",((2*i)-1)); i++; } }
Output
If we run the above program then it will generate the following output
1 3 5 7 9
Advertisements