This is a program that takes a number as input from the user and then prints its square.
C program:-
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
//*program that can calculate square of a number
int nmbr,sqr;
clrscr();
printf("Enter the number which you want the square\n");
scanf("%d",&nmbr);
sqr=pow(nmbr,2);
printf("the square of %d is %d\n",nmbr,sqr);
getch();
}
C program:-
#include<stdio.h>
#include<conio.h>
void main(void)
{
//*program that can calculate square of a numberint nmbr,sqr;
clrscr();
printf("Enter the number which you want the square=");
scanf("%d",&nmbr);
sqr=nmbr*nmbr;
printf("\n The square of %d is %d\n",nmbr,sqr);
getch();
}
Output:-
Enter the number which you want the square= 3
The square of 3 is 9
Second Method:-
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
//*program that can calculate square of a number
int nmbr,sqr;
clrscr();
printf("Enter the number which you want the square\n");
scanf("%d",&nmbr);
sqr=pow(nmbr,2);
printf("the square of %d is %d\n",nmbr,sqr);
getch();
}
NOTE:-
In this program we use a built in math function "pow" and its syntax is pow(number,exponent); and for using this function we must have to use #include<math.h>
No comments:
Post a Comment