Thursday, 14 April 2016

C And C++ Program to read and print elements in an array Problem Solution.


C Solution:

#include <stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){
    int i,arr[10];

    printf("Enter 10 elements in the array : ");

    for(i = 0; i < 10; i++) scanf("%d", &arr[i]);

    printf("\nElements in array are: ");

    for(i=0; i<10; i++) printf("%d ", arr[i]);

    return 0;
}

C++ Solution:

#include <iostream>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){
    int arr[10];

    cout << "Enter 10 elements in the array : ";

    for(int i = 0; i < 10; i++) cin >> arr[i];

    cout << endl <<"Elements in array are: ";

    for(int i=0; i<10; i++) cout << arr[i] << " ";

    return 0;
}

No comments:

Post a Comment