C C++ program to find largest maximum element in Array

Coding in C

#include<stdio.h>
int main()
{
    int num[5],i,large;
    printf("Enter elements of array: \n");
    for(i=0;i<5;i++)
    {
        scanf("%d",&num[i]);
    }
    large=num[0];
    for(i=0;i<5;i++)
    {
        if(num[i]>large)
        {
            large=num[i];
        }
    }
    printf("Largest element = %d\n",large);
    return 0;
 }

Coding in C++

#include<iostream>
using namespace std;
int main()
{
    int num[5],i,large;
    cout<<"Enter elements of array: \n";
    for(i=0;i<5;i++)
    {
        cin>>num[i];
    }
    large=num[0];
    for(i=0;i<5;i++)
    {
        if(num[i]>large)
        {
            large=num[i];
        }
    }
    cout<<"Largest element = "<<large;
    return 0;
 }

Output

C CPP program to find largest element in Array

Published by

admin

I am a computer teacher, programmer and web developer