Answer to Question #182414 in C++ for Hammad

Question #182414

USING ARRAYS

Q 4) Write a program to compute the following mathematical equation:

k=0nAk*B[n-k] Where n = 9

Q 5) Create a program to enter 20 elements into an array, create another array to copy only elements to the new array which are even and three digit. All other digits are to be replaced by maximum positive value.


1
Expert's answer
2021-04-18T23:16:35-0400
5.#include<bits/stdc++.h>
using namespace std;
int maximum_no(int a[])   //function to find the maximum element of the array
{
    int max_nm;
    max_nm=a[0];
    for(int i=0;i<20;i++)
    {
        if(a[i]>max_nm)
        {
            max_nm=a[i];
        }
    }
    return max_nm;
}
int main()
{
    int a[20],e[20],i,temp,s,max_nm;
    cout<<"Input elements of first array ";
    for(i=0;i<4;i++)
    {
        cin>>a[i];
    }
    max_nm=maximum_no(a);
    for(i=0;i<20;i++)
    {
        s=a[i]/100;
        if(s>=1 && s<10)
        {
            if(a[i]%2==0)
            {
                e[i]=a[i];
            }
            else
            {
                e[i]=max_nm;
            }
        }
        else
        {
            e[i]=max_nm;
        }
    }
    cout<<"\nNew array is ";
    for(i=0;i<20;i++)
    {
        cout<<e[i]<<"\n";
    }


}

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
APPROVED BY CLIENTS