Below is a C program which accepts a maximum of 10 numbers from the user, stores them in an array and prints them back.
/*Program to read n numbers into an array and print them*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],num,i;
printf("Enter the number of elements:");
scanf("%d",&num);
if(num>10)
{
printf("No of elements cannot be more than 10. Try again..!");
}
else
{
/*Reading array elements*/
for(i=0;i<num;i++)
scanf("%d",&a[i]);
/*Printing the array elements*/
printf("Elements in the array are:\n");
for(i=0;i<num;i++)
printf("%d ",a[i]);
}
getch();
}
Sample input and output:
Enter the number of elements:6
1 3 5 7 9 0
Elements in the array are:
1 3 5 7 9 0
No comments:
Post a Comment