Square root of array data structure by R4R Team

Example-
array is {8,27,64,125}
Square root is {2,3,4,5}

program-

#include< stdio.h>
#include
int main()
{
int a[100],n,i,j,t;
printf("Enter number of elements\n");
scanf("%d",&n);
printf("Enter %d number in array\n",n);
//input in array
for(i=0;i< n;i++)
{
scanf("%d",&a[i]);
}
//Square root the numbers
for(i=0;i< n;i++)
{
a[i]=pow(a[i],0.5);
}
//Now traverse
printf("After Square root\n");
for(i=0;i {
printf("%d,",a[i]);
}
}


output-

Enter number of elements
Enter 5 number in array
4 9 16 25 36
After Square root
2,3,4,5,6,

-In this program, we take a input of numbers in the array.
-pow() function is the predefined in math library so we include it.
-We run loop for each and every elements in array and apply pow(a[i],0.5) function to find the square root of each elements.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!