Problem In Hand
C Program to take input for a numbers calculate and print its square and cube
Process and Solution Of Problem
* Take input for a number and store in a variable
* calculate and store its square in second variable
* calculate and store its cube in third variable
* further display square and cube
Program/Source Code
#include <stdio.h>
int main()
{
int n,s,c;
printf("Enter any no ");
scanf("%d",&n);
s=n*n;
c=n*n*n;
printf("Square = %d\n",s);
printf("Cube = %d\n",c);
printf("Square = %d Cube = %d\n",s,c);
return 0;
}
Program Explanation
On execution of the program
* user enteres any number and it is stored in a variable “n”
* calculation is performed and its square is stored in “s”.
* calculation is performed and its cube is stored in “c”.
* then square and cube is displayed on the screen
Output:
Enter any no 5 Square = 25 Cube = 125 Square = 25 Cube = 125
You May Also Like:
C Program to find lowest of 3 numbers
C Program to print factorial of a number
C program to check number is even, odd or zero
C program to check a character is an alphabet or not
C program to convert total meters to km and m
| <<< Previous: Product of three numbers | Sum, Product and Difference of 2 Numbers : Next >>> |
Tutorials | Technical Questions | Interview Questions |
|---|---|---|
|
C Programming C++ Programming Class 11 (Python) Class 12 (Python) |
C Language C++ Programming Python |
C Interview Questions C++ Interview Questions |




