Pages

How to enter the value of an array by user

//How to enter the value of an array by user.


#include<stdio.h>
#include<conio.h>

void main() {
  int a[5];//Decalre the array and 5 is the size of an array
  //whose index is started from 0.
  int i;
  clrscr();
  printf("Enter the value of an array:\n");
  for(i=0;i<5;i++)
  {
   scanf("\n%d",&a[i]);
  }
  printf("\n\nYou entered following values in array:");
  for(i=0;i<5;i++)
  {
   printf("\na[%d]=%d",i,a[i]);
  }
 
  getch();
}

Output:

Enter the value of an array:
1
2
3
4
5



You entered following values in array:
a[0]:1
a[1]:2
a[2]:3
a[3]:4
a[4]:5

No comments:

Post a Comment