Friday, 9 January 2015

C Program to Decrement all the elements in an array

This is C Program which decrements all the elements  in the array by 1.

Here we read all the elements in the array and then decrement its value by 1 and then print it again.

PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,n;
    printf("How many numbers? \t");
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
    {
        printf("Enter number %d : \t",i+1);
        scanf("%d",&a[i]);
    }
    printf("\nOriginal array is :\t");
    for(i=0;i<n;i++)
        printf("%d \t",a[i]);

    printf("\n\nDecremented Array is:\t");
    for(i=0;i<n;i++)
    {
        a[i]--;
        printf("%d\t",a[i]);
    }

    return 0;
}

OUTPUT :
C - Decrement all the elements in an array

No comments:

Post a Comment