Perfect Squares - Till N - C - Spicy Coders

Recent

Thursday, September 28, 2017

Perfect Squares - Till N - C

Given a positive integer N as the input, print all the perfect squares till N (inclusive of N). 

Input Format: The first line contains N. 

Output Format: The first line contains the perfect squares till N separated by a space. 

Boundary Conditions: 1 <= N <= 9999999 

Example Input/Output 1: 
Input: 
20 

Output: 
1 4 9 16 

Example Input/Output 2: 
Input: 

Output: 
1

Source Code:

#include<stdio.h>
int main() {
   int i,N;
   scanf("%d",&N);
   for(i=1;i<=10000;i++)
   {
       if(i*i<=N)
            printf("%d ",i*i);
   }

}

No comments:

Post a Comment