C Exercises: Check whether a given number is a perfect cube or not
C Numbers: Exercise-29 with Solution
Write a program in C to check whether a given number is an ideal cube or not.
Test DataInput a number: 125
Sample Solution:
C Code:
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
int main()
{
int num, curoot,ans;
printf("\n\n Check whether a number is a perfect cube or not: \n");
printf(" -----------------------------------------------------\n");
printf(" Input a number: ");
scanf("%d",&num);
curoot=round(pow(num, 1.0/3.0));
if(curoot*curoot*curoot==num)
{
printf(" The number is a perfect Cube of %d \n",curoot);
}
else
{
printf(" The number is not a perfect Cube.\n");
}
}
Sample Output:
Input a number: 125 The number is a perfect Cube of 5
Pictorial Presentation:
Flowchart:

C Programming Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a program in C to find circular prime numbers upto a specific limit.
Next: Write a program in C to display first 10 Fermat numbers.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
C Programming: Tips of the Day
It is more efficient to use if-return-return or if-else-return?
Since the return statement terminates the execution of the current function, the two forms are equivalent (although the second one is arguably more readable than the first).
The efficiency of both forms is comparable, the underlying machine code has to perform a jump if the if condition is false anyway.
Note that Python supports a syntax that allows you to use only one return statement in your case:
return A+1 if A > B else A-1
Ref : https://bit.ly/2S4P2he
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook