×

C Programs

C Basic & Conditional Programs

C Looping Programs

C String Programs

C Miscellaneous Programs

C program to print alternate elements of the array

Here, we are going to learn how to print alternate elements of the array in C programming language?
Submitted by Nidhi, on July 10, 2021

Problem statement

Here, we will create an array of integers then print alternate elements of an array on the console screen.

Printing alternate elements of the array

The source code to print alternate elements of the array is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

C program to print alternate elements of the array

// C program to print alternate elements of array.

#include <stdio.h>

int main()
{
    int arr[] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 10 };
    int i = 0;

    printf("Alternate elements of array: ");
    for (i = 0; i < 10; i = i + 2)
        printf("\n\tarr[%d] is: %d", i, arr[i]);

    printf("\n");
    return 0;
}

Output

Alternate elements of array: 
	arr[0] is: 10
	arr[2] is: 30
	arr[4] is: 50
	arr[6] is: 70
	arr[8] is: 90

Explanation

Here, we created an array arr with 10 elements, and then we increased the value of the counter variable i by 2 in the for loop to print alternate elements of an array on the console screen.

C One-Dimensional Array Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.