Programming Examples

Write a program to find perfect cubes up to a given number


Write a program to find perfect cubes up to a given number.

/ 1, 8, 27, 64 are perfect cubes of 1, 2, 3 and 4 /.

Solution

# include<math.h>
void main()
{
int i, j, k;
clrscr();
printf(“Enter a Number :”);
scanf(“%d”,&k);
for(i=1;i<k;i++)
{
 for(j=1;j<=i;j++)
 {
 if(i==pow(j,3))
 printf(“\nNumber : %d & it’s Cube :%d”,j,i);
 }
}
getch();
}
▶ RUN

Output/ Explanation:

OUTPUT:

Enter a Number : 100

Number : 1 & it’s Cube : 1

Number : 2 & it’s Cube : 8

Number : 3 & it’s Cube : 27

Number : 4 & it’s Cube : 64

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad