In this C program, the user enters a number and you have to calculate its square and cube.
Prerequisite knowledge:
- Basic syntax.
- Basic mathematics.
Program: C program to find the square and cube of a number
#include<stdio.h> int main() { int a,sq,cube; printf("Enter a number: "); scanf("%d",&a); sq=a*a; /*calculating square*/ cube=a*a*a; /*calculating cube*/ printf("\nSquare= %d \nCube= %d\n",sq,cube); return 0; }
Output:
Enter a number: 13
Square= 169
Cube= 2197
Do share your code ideas in the comment section to help other beginners.