Cube Root of Number
/***************************************************** Cube Root of Number ******************************************************/ #include< stdio.h> #include< conio.h> int qube(int); void main() { int num, ans; clrscr(); printf("Enter any number"); scanf("%d",&num); ans=pow(num, 0.3; ans++; printf("\n\Cube of %d is: %d",num,qube(num)); getch(); }
Output
Enter any Number: 27 Cube of 27 is: 3
Explanation of Program
- Here we receive any number from keyboard and after that we multiplynumber by 0.33333 because square root of any number means power of1/3 and 1/3=0.33333.
- pow() is a predefined function in math.h header file, it is used forcalculate power of any number.
Cube Root of Number using user defined function
/***************************************************** Cube Root of Number ******************************************************/ #include< stdio.h> #include< conio.h> int qube(int); void main() { int num; clrscr(); printf("Enter any number"); scanf("%d",&num); printf("\n\Cube of %d is: %d",num,qube(num)); getch(); } int qube(int num) { int ans; ans=pow(num, 0.3; ans++; return(ans); getch(); }
Output
Enter any Number: 64 Cube of 64 is: 4
Explanation of Program
- Here we receive any number from keyboard and after that we multiplynumber by 0.33333 because square root of any number means power of1/3 and 1/3=0.33333.
- pow() is a predefined function in math.h header file, it is used forcalculate power of any number.
No comments:
Post a Comment