This program will read an array and print that array as output. In this program, we have used the for loop to print all elements of an array. When you execute this program, It will ask to enter the number of array elements and then take elements as input and store in an array variable.
Let assume if you enter the number of elements as 2, then you need to enter two elements as input. see the below program output.
Copy the below c program and execute it with the help of c compiler.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include<stdio.h> int main() { int i, arr[50], num; printf("\nEnter no of elements:"); scanf("%d", &num); //Reading values into Array printf("\nEnter the values :"); for (i = 0; i < num; i++) { scanf("%d", &arr[i]); } //Printing of all elements of array for (i = 0; i < num; i++) { printf("\narr[%d] = %d", i, arr[i]); } return (0); } |
Enter no of elements :2
Enter the values :50
90
arr[0] = 50
arr[1] = 90
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: c program, c program examples, c program examples with output, c programs, c programs with solutions, list of important c programs