1. Write a program to find the largest odd number in a 50-element array of integ
ID: 3545994 • Letter: 1
Question
1. Write a program to find the largest odd number in a 50-element array of integers. You must
use two functions or procedures, one to input values into the array and another to find the
largest odd number in the array.
Use the following sample input:
30 55 39 290 398 96 900 10 33 22
35 46 67 35 55 555 456 23 432 100
30 90 808 898 999 80 25 321 215 276
27 89 40 80 90 356 89 201 214 973
12 53 289 80 799 68 89 854 678 981
2. Write a program for the following:
Assume that your computer has the very limited capability of being able to read and write
only single-integer digits and to add two integers consisting of one decimal digit each. Write a
program that can read two integers up to 30 digits each, add these integers together, and
display the result. Test your program using pairs of numbers of varying lengths.
Hint: Store the two numbers in two int arrays of size 30, one digit per array element. If the
number is less than 30 digits in length, enter enough leading zeros (to the left of the number)
to make the number 30 digits long.
You will need a loop to add the digits in corresponding array elements. Don
Explanation / Answer
//here is your first programme
#include<iostream>
using namespace std;
#define N 50
void takeInputToArray(int[]);
int findMaxOddNumber(int []);
int main()
{
int A[N];
int maxOdd;
takeInputToArray(A);
maxOdd=findMaxOddNumber(A);
if(maxOdd==-1)
{
cout<<"No odd number found ";
}
else
{
cout<<"Maximum Odd Number in given array is :"<<maxOdd;
}
return 0;
}
void takeInputToArray(int A[])
{
cout<<"Enter 50 numbers here :";
for(int i=0;i<N;i++)
cin>>A[i];
}
int findMaxOddNumber(int A[])
{
int res=-1;
for(int i=0;i<N;i++)
{
if(A[i]%2!=0&&A[i]>res)
res=A[i];
}
return res;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.