Program to find square of all elements of an array
Program:
Output:
#include<stdio.h>
void main()
{
int i;
float a[5],b[5];
printf("Enter float array of whose you
want to find square: \n");
for(i=0;i<5;i++)
{
scanf("%f",&a[i]);
b[i]=a[i]*a[i];
}
printf("\nSquare of entered array is:
\n");
for(i=0;i<5;i++)
{
printf("%f\n",b[i]);
}
}Output:
Explanation:
As seen in program we have created another array to store square of first array we can also store square in same array by replacing b[i]=a[i]*a[i] by a[i]=a[i]*a[i].
This will lead to less memory usage.
Since no second array is created so our memory is saved.
No comments:
Post a Comment