Home » C Basic I/O programs

C program to find cube of an integer number using two different methods

In this C program, we are going to find cube of an integer number. Here, we will implement the program by using two methods 1) without using pow() function and 2) using pow() function.
Submitted by Manju Tomar, on September 20, 2017

A cube can be found by calculating the power of 3 of any number. For example, the cube of 2 will be 23 (2 to the power of 3).

Here, we are implementing this program by using two methods:

  1. Without using pow() function
  2. With using pow() function

1) Without using pow() function

In this method, we will just read an integer number and multiply it 3 times.

Consider the program:



#include <stdio.h>

int  main()
{

    int a,cube;
    
    printf("Enter any integer number: ");
    scanf("%d",&a);
    //calculating cube
    cube = (a*a*a);
    printf("CUBE is: %d\n",cube);
    
    return 0;
}

Output

Enter any integer number: 8
CUBE is: 512

2) Using pow() function

pow() is a library function of math.h header file, it is used to calculate power of any number. Here, we will use this function to find the cube of a given number.

Consider the program:



#include <stdio.h>
#include <math.h>

int  main()
{

    int a,cube;
    
    printf("Enter any integer number: ");
    scanf("%d",&a);
    //calculating cube
    cube = pow(a,3);
    printf("CUBE is: %d\n",cube);
    
    return 0;
}

Output

Enter any integer number: 8
CUBE is: 512

"This is very basic program in C programming language and will be helpful for those who started learning C programming, if you liked, please write comments..."






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.