Friday 10 November 2017

C Program to Increment every Element of the Array by one & Print Incremented Array


Code:

#include

void incrementArray(int[]);

void main()
{
    int i;
    int array[4] = {10, 20, 30, 40};

    incrementArray(array);
    for (i = 0; i < 4; i++)
       printf("%d\t", array[i]);   // Prints 2, 3, 4, 5
}

void incrementArray(int arr[])
{
    int i;

    for (i = 0; i < 4; i++)
        arr[i]++;     // this alters values in array in main()
}

Output:

11    21    31

More C Programs:


















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...