In this program, the task is to take input of n no. of elements in & store it in array . Here , n is the no. of elements in array & Using for loop , we will get the values in order of a[0] , a[1] , - - - - till a[n] . Afterthat, the array id displayed using for loop.
#include<stdio.h>
#include<conio.h>
void main()
{ int a[20],i=0,n;
clrscr();
printf("\n program to input & desplay elements of array");
printf("\n\n enter no. of elements in array (max 20) : ");
scanf("%d",&n);
printf(" now enter them : \n");
for(i=0;i<n;i++)
{ printf("enter a[%d] = ",i);
scanf("%d",&a[i]);
}
printf("\n\n displaying them : \n");
for(i=0;i<n;i++)
{ printf("a[%d] = %d \n",i,a[i]);
}
getch();
}
Input elements in array :-
#include<conio.h>
void main()
{ int a[20],i=0,n;
clrscr();
printf("\n program to input & desplay elements of array");
printf("\n\n enter no. of elements in array (max 20) : ");
scanf("%d",&n);
printf(" now enter them : \n");
for(i=0;i<n;i++)
{ printf("enter a[%d] = ",i);
scanf("%d",&a[i]);
}
printf("\n\n displaying them : \n");
for(i=0;i<n;i++)
{ printf("a[%d] = %d \n",i,a[i]);
}
getch();
}

No comments:
Post a Comment
Guys if you think something is wrong or should be edit than please do comment.