In this tutorial you will learn about the C Program to Print Array Elements at Odd Position and its application with practical example.
C Program to Print Array Elements at Odd Position
In this tutorial, we will learn to create a C program that will Print Array Elements at Odd Positions in C programming.
Prerequisites
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 Odd 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 Odd Positions C Programming Language.
With the help of this program, we can Print Array Elements at Odd Positions.
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 |
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 odd index values. 6. End the program. |
Program to Print Array Elements at Odd Positions:-
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 |
#include<stdio.h> int main() { //declaring the variables for the program. int i; char arry[10][32]; //adding the elements in the array. arry[10][32] = {"Abraham Lincoln", "Mother Teresa", "Martin Luther King", "Nelson Mandela", "Muhammad Ali", "Mahatma Gandhi", "Winston Churchill ", "Christopher Columbus", "Charles Darwin", "Neil Armstrong"}; //Printing the array elements located on the odd positions printf("Elements on Odd Position:\n"); for(i = 0; i < 10; i++){ if((i+1) % 2 != 0){ printf("\n%s", arry[i]); } } printf("\n"); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- arry[10][32] = it will hold the string value.
- i = it will hold the integer value for controlling the loop.
Insert the elements in the array for printing the odd index values.
Printing the array elements of the odd index values in the output.