In this tutorial you will learn about the C Program to Print Array Elements at Even Position and its application with practical example.
C Program to Print Array Elements at Even Position
In this tutorial, we will learn to create a C program that will Print Array Elements at Even Positions in C programming.
Before starting with this tutorial we assume that you are 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.
- Conditional Statements in C programming.
- Arithmetic Operators in C programming.
Print Array Elements at Even Positions
As we all know array is a collection of similar data type elements. In an array, only one variable is declared which can store multiple values. First will take the number of elements of an array from the user. Then will take the elements from the user for the array. And at last, we will Print Array Elements at Even Positions C Programming Language.
With the help of this program, we can Print Array Elements at Even Positions.
1. Declare the variables for the program.
2. Take making the array.
3. Adding the elements in the array.
4. Sending that array to the for loop.
5. Print the elements of array of the <strong>Even </strong>index values.
6. End the program.
Program to Print Array Elements at Even Positions:-
/* C Program to Print Array Elements at Even Position */
//declaring the variables for the program.
int arr, i;
//adding the elements in the array by taking input from the user.
printf("Enter any 10 array elements: ");
//input for loop to take elements of array
for(i=0; i<10; i++)
//printing the output of the program
printf("\nValues stored at even position are:\n");
for(i=0; i<10; i++)
//Printing the array elements located on the Even positions
printf("%d ", arr[i]);
In the above program, we have first initialized the required variable.
- arry = it will hold the string value.
- i = it will hold the integer value for controlling the loop.
Getting the elements in the array for printing the Even index values.
For Loop for input.
Calculating the array elements of the Even index values.
Printing the output for the Even Index values.