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.
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";
}
}
Comments
Leave a comment