Answer to Question #199349 in C++ for AIMAN hilmi

Question #199349

1) Write a program in C++ that is able to determine and display the largest and the smallest number among any number of integers entered by the user.


2) Write a program in C++ that is capable of displaying how many numbers from 0 to 100 that are divisible by 2 and 5.




1
Expert's answer
2021-05-27T11:31:10-0400

(1)

#include <iostream>
using namespace std;
int main()
{
    int num,i,j,temp;
    cout<<"Enter the number of elements in the array : ";
    cin>>num;
    int arr[num];
    cout<<"Enter the elements of array : ";
    for(int i=0;i<num;i++)
    {
        cin>>arr[i];
    }
    for (i = 0; i < num; ++i)
        {
            for (j = i + 1; j < num; ++j)
            {
                if (arr[i] > arr[j])
                {
                    temp =  arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
           }
        }
    cout<<"Smallest number in the array : "<<arr[0];
    cout<<"\nLargest number in the array : "<<arr[num-1];
}

(2)

#include <iostream>
using namespace std;
int main()
{
    int d2=0,d5=0,i;
    for(i=1;i<=100;i++)
    {
        if(i%2==0)
        {
            d2=d2+1;
        }
        if(i%5==0)
        {
            d5=d5+1;
        }
    }
    cout<<"Numbers divisible by 2 = "<<d2;
    cout<<"\nNumbers divisible by 5 = "<<d5;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog