Advertisement
fahimkamal63

Sum of two number in array

Apr 19th, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5.     int t; cin >> t;
  6.     while(t--){
  7.         int n, m; cin >> n >> m;
  8.         unsigned long long int first_num = 0, second_num = 0, i, temp;
  9.         //  Taking input of First array
  10.         for(i = 0; i < n; i++){
  11.             cin >> temp;
  12.             first_num *= 10;
  13.             first_num += temp;
  14.         }
  15.         //  Taking input of Second array
  16.         for(i = 0; i < m; i++){
  17.             cin >> temp;
  18.             second_num *= 10;
  19.             second_num += temp;
  20.         }
  21.         //  Adding them together
  22.         temp = first_num + second_num;
  23.  
  24.         //  Making the result array
  25.         int index = 0;
  26.         int k = temp;
  27.         while(k){
  28.             k /= 10;
  29.             index++;
  30.         }
  31.         int result[index];
  32.         //k = index;
  33.         for(i = index-1; i > -1; i--){
  34.             result[i] = temp % 10;
  35.             temp /= 10;
  36.         }
  37.         //  Showing the result
  38.         for(i = 0; i < index; i++) cout << result[i] << ' ';
  39.         cout << endl;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement