In the previous post we saw the average of three numbers. Now, we will see how to square of a number in C.
Basic Data Type:- int, char, float, double
int Datatype:- Its an integer datatype .Its of 2 bytes .Its range is −32,768 to 32,767.
char Datatype:-Its an character datatype. Its of 1 byte. Its range is -128 to 127 .
float Datatype:-Its for floating point numbers. Its of 4 byte.
double Datatype :-Its for large floating point numbers .Its of 8 byte
Code for square of a number :-
#include <stdio.h>
int main()
{
int n1,square;
printf("Enter a number");
scanf("%d",&n1);
square=n1*n1;
printf("The square of the number is %d ",square);
return 0;
}
Algorithm:-
1.Start
2.Declare a variable called n1 which is known as number.
3.Get the input for the n1 variable using scanf statement by using "%d" specifier .
4.Declare a square variable where we will multiply the n1 variable with a n1 variable .
Explanation:-Since its square we have to multiply the number * number.
5.Finally print using the statement "The square of a number is " and print the square variable
6.Stop.
Screenshot:-
1.Code Screenshot:-
2.Output Screenshot:-
In the next blog we will see about calculating simple interest in C.
0 Comments