Description
To find Sqauares of all numbers from 1 to given range, take a loop from 1 to given range and find the sqaures of all numbers in that range.
C/C++
/* C Program to print all squares of numbers from 1 to given Range */ //Save it as SquareNumbers.c #include<stdio.h> int main(){ int i, n; printf("Enter Range : "); scanf("%d",&n); printf("The squares in given range : \n"); for(i=1;i<=n;i++){ printf("%d\n", i*i); } return 0; }
Input: Enter range : 5 Output: The squares in given range : 1 4 9 16 25
Java
/* Java Program to print all squares of numbers from 1 to given Range */ //Save it as SquareNumbers.java import java.io.*; import java.util.Scanner; public class SquareNumbers { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter range : "); int n = scanner.nextInt(); System.out.println("The squares in given range : "); for(int i=1;i<=n;i++) { System.out.println(i*i); } } }
Input: Enter range : 5 Output: The squares in given range : 1 4 9 16 25
Related programs
1) Program to Check Whether a Number is Prime or Not2) Program to Check Whether a Number is Even or Odd
3) Check whether a given number is a perfect number or not
4) Program to find all prime numbers in given range
5) Program to find the average of numbers in a given range
6) Program to generate Random number in a given Range
7) Program to calculate Gross Salary
8) Program to calculate percentage mark of student
9) Program to reverse a number
10) Program to display multiplication table of a number