Program to accept and display an array

Program to accept and display an array


Program:


#include<stdio.h>
void main()
{
int i;
float a[5];
printf("Enter float array: \n");
for(i=0;i<5;i++)
{
scanf("%f",&a[i]);
}
printf("\nEntered array is: \n");
for(i=0;i<5;i++)
{
printf("%f\n",a[i]);
}
}

Output:



Explanation:

Our task here is to accept an array from user and display it.
But, we know that array starts from 0 and ends at (n-1)th position.
So, we have used a for loop from 0 to n-1.
We can accept double or int array also.


No comments:

Post a Comment