Computer Science, asked by dhanamvijay2002, 11 months ago

Please help me FRIENDS...

Write a C++ program for this question.

The input for this program consists of numbers n, a0, a1, ..., a{n-1}, b0, b1, b{n-1}.  In this, ai and bi are supposed to be the ith least significant digits of numbers A, B.  You are supposed to print the digits of the sum of A, B, again from least significant to the most significant - one per line. Note that the sum can have n+1 digits, and so you should print n+1 digits, with the most significant digit being possibly 0.You may assume that the size of an array can be a value that is known only during execution.  For example, it is OK to write 

"int n; cin >>n; int A[n];"

Attachments:

Answers

Answered by devsaini115
0

Answer:

I don't know because I am in 5th standard

Answered by Anonymous
1

Answer:

#include<stdio.h>

#include<simplecpp>

int main()

{

int sum = 0, rem = 0, t =0;

 int a[50][50];

 int n, m=2;

 cin>> n;

 for(int i = 0; i< m; i++)

 {

   for(int j = 0; j < n; j++)

   {

     cin>>a[i][j];

   }

 }

 for(int i = 0; i<m; i++)

 {

   for(int j = 0; j< n; j++)

   {

   if(t < n)

       {

       t= t+1;

       sum = rem + (a[i][j] + a[i+1][j]);

       rem = sum/10;

       sum = sum%10;

       cout << sum << endl;

       }

   }

   }

       cout<< rem << endl;

}

Explanation:

the remaining ie the first digit eg(20/ 10 = 2) must be added to the next digit and it needs to be continued till end

then the carried digits has to be printed at the end

hope you understand it :)

Similar questions