This c program will calculate the square and cube of any given number. We will also perform this by the use of functions.
C Program To Find Square and Cube Of A Number
#include<stdio.h> #include<conio.h> void main() { int a,s,c; clrscr(); printf("\n Enter A Number: "); scanf("%d",&a); s=a*a; //Square = number * number c=s*a; //Cube = Square * number printf("\n Square of %d is = %d",a,s); printf("\n\n Cube of %d is = %d",a,c); getch(); }
Output :
C Program To Determine Square and Cube of Number Using Function
#include<stdio.h> #include<conio.h> int square(int m); int cube(int n); void main() { int x,s,c; clrscr(); printf("\n Enter Any Number : "); scanf("%d",&x); s=square(x); c=cube(x); printf("\n Square of %d is = %d",x,s); printf("\n\n Cube of %d is = %d",x,c); getch(); } int square(int m) { return(m*m); } int cube(int n) { return(n*n*n); }
Dev C++ Code to Find the Square and Cube using Function
#include<stdio.h> int square(int m); int cube(int n); void main() { int x,s,c; printf("\n Enter Any Number : "); scanf("%d",&x); s=square(x); c=cube(x); printf("\n Square of %d is = %d",x,s); printf("\n\n Cube of %d is = %d",x,c); getch(); } int square(int m) { return(m*m); } int cube(int n) { return(n*n*n); }
Output :