C C++ program for declaration and initialization of array

Coding in C

#include<stdio.h>
int main()
{
    int a[5]={5,1,9,7,2};
    printf("Number1 = %d",a[0]);
    printf("\nNumber2 = %d",a[1]);
    printf("\nNumber3 = %d",a[2]);
    printf("\nNumber4 = %d",a[3]);
    printf("\nNumber5 = %d",a[4]);
    return 0;
}

Coding in C++

#include<iostream>
using namespace std;
int main()
{
    int a[5]={5,1,9,7,2};
    cout<<"Number1 = "<<a[0]<<endl;
    cout<<"Number2 = "<<a[1]<<endl;
    cout<<"Number3 = "<<a[2]<<endl;
    cout<<"Number4 = "<<a[3]<<endl;
    cout<<"Number5 = "<<a[4]<<endl;
    return 0;
 }

Output

Program for Declaration and initialization of array in C C++

Published by

admin

I am a computer teacher, programmer and web developer