Problem statement:- Program to find the square of a number.
Data requirement:-
Input Data:- num
Output Data:-sqr
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++
int main()
{
int num,sqr;
cout<<"Enter a number:";
cin>>num;
sqr=num*num;
cout<<"Square of the number:"<<sqr;
}
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 PythonHere 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
Square of the number:625
Program in Java
Code:Here is the source code of the Java Program to Find the square of a number.
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();
}
}
Enter a number:
77
Square of the number: 5929
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
Enter a number:33
Square of the number: 1089
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box