Question

2. Write a Marie program that accepts two positive (inputs) two integers and outputs the sum...

2. Write a Marie program that accepts two positive (inputs) two integers and outputs the sum of both of the integers and all the numbers in between

Write a Marie program that determines the largest of a series of positive integers provided by a user. The user will enter a -1 when she is finished. Up to 10 numbers will be provided by the user.

Write a Marie program that accepts two positive integers, multiples them by repeated addition, and outputs the result.

Write a Marie program that accepts 4 positive integers and outputs them in ascending order.

Write a Marie program of 40 lines or less that accepts 15 positive integers and outputs the maximum number that was provided by the user. You need to use a loop to input the numbers and determine the max value.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;
int getnum(string mess,int[]);
int add(int [], int [],int[] ,int,int);
void print(int a[],int);
bool checkinput(string);
int main()
{int a[21];
int b[21];
int c[51];
int i, lena,lenb,lenc;
lena=getnum("first number: ",a);
cout<<endl;
lenb=getnum("second number: ",b);
lenc=add(a,b,c,lena,lenb);
cout<<"    ";
print(a,lena);
cout<<"+ ";
print(b,lenb);
for(i=0;i<lenc+5;i++)
    cout<<"-";
cout<<"\n    ";
print(c,lenc);
system("pause");
return 0;
}
bool checkinput(string in)
{int i;
if(in.length()>20)
      return false;
for(i=0;i<in.length();i++)
     if(in[i]<'0'||in[i]>'9')
          {cout<<"invalid input\n";
          return false;
          }
return true;
}
int getnum(string mess,int a[])
{int i;
for(i=0;i<21;i++)
    a[i]=0;
string input;
cout<<"Enter "<<mess;
cin>>input;
while(!checkinput(input))
    {cout<<"Enter "<<mess;
     cin>>input;
     }
for(i=0;i<input.length();i++)
     a[input.length()-1-i]=input[i]-'0';
return input.length();
}
int add(int a[], int b[],int c[],int lena,int lenb)
{int i,n,carry=0,d;
cout<<endl;
for(i=0;i<21;i++)
    c[i]=0;
if(lena>lenb)
    n=lena;
else
    n=lenb;
   
for(i=0;i<n;i++)
    {d=a[i]+b[i]+carry;
      c[i]=d%10;
      carry=d/10;
      }
if(carry==0)
   return n;
else
   c[i]=carry;
    
return n+1;
}
void print(int a[],int len)
{int i;
for(i=len-1;i>=0;i--)
       cout<<a[i];
cout<<endl;
}

Add a comment
Know the answer?
Add Answer to:
2. Write a Marie program that accepts two positive (inputs) two integers and outputs the sum...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT