C program to find the square and cube of a number

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.

About ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ

Linux and Python enthusiast, in love with open source since 2014, Writer at programming-articles.com, India.

View all posts by ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ →

Leave a Reply

Your email address will not be published. Required fields are marked *