C C++ program to find smallest minimum element in array

Coding in C

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

Coding in C++

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

Output

C C++ program to find smallest element in array

Published by

admin

I am a computer teacher, programmer and web developer