Squre Root of any Number
/**************************************************** Squre Root of any Number *****************************************************/ #include< stdio.h> #include< conio.h> #include< math.h> void main() { int num,ans; clrscr(); printf("Enter any Number: "); scanf("%d",&num); ans=pow(num,0.5); printf("\n Squre of %d is: %d",num,ans); getch(); }
Output
Enter any Number: 9 Squre of 9 is: 3
Explanation of Program
- For calculate sqare root of number we multiply number by 0.5 because square root of any number means power of 1/2 and 1/2=0.5.
- pow() is a predefined function in math.h header file, it is used forcalculate power of any number.
Squre Root of Numberr By passing values in Function
/**************************************************** Squre Root of any Number *****************************************************/ #include< stdio.h> #include< conio.h> #include< math.h> int squre(int); void main() { int num; clrscr(); printf("Enter any Number: "); scanf("%d",&num); printf("\n Squre of %d is: %d",num,squre(num)); getch(); } int squre(int num) { int ans; ans=pow(num,0.5); return(ans); getch(); }
Output
Enter any Number: 64 Squre of 64 is: 8
No comments:
Post a Comment