Wednesday 14 January 2015

Cpp Program to decrement all the elements in an array by one

This is a Cpp Program which decrements all the elements in an array by one.

Here we read all the elements in the array and print them all again each time decrementing its value by one.

PROGRAM :
#include <iostream>

using namespace std;

int main()
{
    int i,n;
    
    cout << "\nEnter the no of Elements: \t";
    cin >> n;
    int arr[n];
    for(i=0;i<n;i++)
    {
        cout << "\nEnter Element " <<  i+1 << ": \t";
        cin >> arr[i];
    }
    cout << "\nOriginal array is :\t";
    for(i=0;i<n;i++)
    cout << arr[i] << "\t";
    
    cout << "\n\nDecrementted array is :\t";
    for(i=0;i<n;i=i++){
        arr[i]--;
    cout << arr[i] << "\t";}
    return 0;
}

OUTPUT :
Cpp - Decrement all the elements in an array

No comments:

Post a Comment