User Input Array in C programming is a collection of the data items taken from the user, which is accessed by using common name. we use two types of arrays in C programming one and two-dimensional array.
#include<stdio.h>
#include<conio.h>
void main()
{
printf("Please Enter Integers:\n");
int arr[5]; //'arr' is name of Array and 5 is length.
for(int i = 0; i < 5; i++)
{
scanf("%d", &arr[i]); //user entered values storing in 'arr' Array.
}
printf("Entered Values:\n");
for(int j = 0; j < 5; j++)
{
printf("%d\n", arr[j]); //printing 'arr' Array Elements.
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
printf("Please Enter Ur Name:\n");
char arr[5]; //'arr' is name of Array and 5 is length.
for(int i = 0; i < 5; i++)
{
scanf("%c", &arr[i]); //user entered values storing in 'arr' Array.
}
printf("Entered Name:\n");
for(int j = 0; j < 5; j++)
{
printf("%c", arr[j]); //printing 'arr' Array Elements.
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
char name[3]; //this is Arrays.
float price[3];
int pages[3], i;
printf("Enter names, prices and no. of pages of 2 books:\n");
for(i = 0 ; i <= 2 ; i++)
{
//User enter values storing in Arrays.
scanf("%c %f %d", &name[i], &price[i], &pages[i]);
}
printf("\nAnd this is what you entered:\n");
for(i = 0 ; i <= 2 ; i++)
{
printf("%c %f %d\n", name[i], price[i], pages[i]); //and printing.
}
getch();
}