In this tutorial you will learn about the C Program to Print Elements in an Array and its application with practical example.
C Program to Print Elements in an Array
In this tutorial, we will learn to create a C program that will Print Elements in an Array using C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- For loop in C programming.
- Arithmetic operations in C Programming.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
Step 1 :- Initialization of the program. Step 2 :- Taking the input size of the array. Step 3 :- Taking the elements of the array from the user for the program. Step 4 :- Using for loop to print the elements of the array to the user. Step 5 :- Ending the execution of the program. |
Printing the Elements in an Array.
In this program, First, we will first take the size of the array from the user. Then we will take the elements of the array from the user. After that, we will use a for loop to print the elements of the array.
With the help of this program, we can be print the elements of the array.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
//C Program to Print Elements in an Array. #include <stdio.h> int main() { //Declaring the required variables for the program int no, i, arr[100]; //i = it will hold the integer value for the loop //no = it will hold the integer value for the input size of array //arr[] = it will hold the integer value for the array. //Taking the input size of the array from the user. printf("Enter the number of elements (1 to 100): "); scanf("%d", &no); //Taking the input elements of the array. for (int i = 0; i < no; ++i) { printf("Enter number %d: ", i + 1); scanf("%d", &arr[i]); } printf("Elements of given array: \n"); //Loop through the array by incrementing value of i for (int i = 0; i < no; i++) { printf("%d ", arr[i]); } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- no = it will hold the integer value.
- i = it will hold the integer value.
- arr[100] = it will hold the integer value.
Taking the size of the array and the elements.
Printing output of the program.