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();
}
Output
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