Pages

Friday, February 5, 2016

C program to read and display 5 integer values in 1-D array.

#include<stdio.h>
int main()
{
int i=0, number[5];
for(i=0; i<5; i++) // This loop tracks array index 
{
printf("Enter your Number[%d]:",i);
scanf("%d",&number[i]);
}
//Logic to print number array.
for(i=0; i<5; i++) // This loop tracks array index 
{
printf("Number[%d]:%d \n", i, number[i]);
}
}

Output of program

Enter your Number[0]:2
Enter your Number[1]:4
Enter your Number[2]:6
Enter your Number[3]:8
Enter your Number[4]:10
Number[0]:2
Number[1]:4
Number[2]:6
Number[3]:8
Number[4]:10

No comments:

Post a Comment