Find the square of a number accept from user

Problem statement:- Program to find the square of a number.

Data requirement:-

   Input Data:- num

  Output Data:-
sqr

Program in C

Here is the source code of the C Program to Find the square of a number.

Code:

#include<stdio.h>
int main()
{
   int num, sqr;
   printf("Enter a number:");
   scanf("%d",&num);
   sqr=num*num;
   printf("Square of the number: %d",sqr);
}

Input/Output:
Enter a number:5
Square of the number: 25

Program in C++

Here is the source code of the C++ Program to Find the square of a number.

Code:


#include<iostream>
using namespace std;
int main()
{
   int num,sqr;
   cout<<"Enter a number:";
   cin>>num;
   sqr=num*num;
   cout<<"Square of the number:"<<sqr;
}

Input/Output:
Enter a number:25
Square of the number:625

Program in Java

Here is the source code of the Java Program to Find the square of a number.

Code:

import java.util.Scanner;
public class SquareOfANumber {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int num, sqr;
   System.out.println("Enter a number:");
   num=cs.nextInt();
   sqr=num*num;
   System.out.println("Square of the number: "+sqr);
   cs.close();
}
}

Input/Output:
Enter a number:
77
Square of the number: 5929

Program in Python

Here is the source code of the Python Program to Find the square of a number.

Code:


num=int(input("Enter a number:")) 
print("Square of the number:",num*num)
 
Input/Output:
Enter a number:33
Square of the number: 1089


Post a Comment

0 Comments