Tuesday, April 21, 2020

C++ Challenge #3 | Sum of First array is Greater than Second Array (Inte...





In this video we are going to solve sum of array sum problem.
let suppose we have two arrays , we have to sum of two arrays and than find which array is greater than other one using c++.
Exam preparations.
interview preparations




here is code

#include <iostream>
using namespace std;
main(){

int num1[5];
int num2[5];
int first_array_sum = 0;
int second_array_sum = 0;

// take input 5 numbers for array 1
cout << "Enter five numbers"<<endl;
for(int i = 0; i < 5; i++){
cin >> num1[i];
}

// take input 5 numbers for array 2
cout << "Enter five numbers"<<endl;
for(int i = 0; i < 5; i++){
cin >> num2[i];
}

// sum of first array
for(int i = 0; i < 5; i++){
first_array_sum += num1[i];
}
// sum of second array
for(int i = 0; i < 5; i++){
second_array_sum += num2[i];
}

cout << "first array sum is " << first_array_sum <<endl;
cout << "second array sum is " <<second_array_sum <<endl;
if(first_array_sum < second_array_sum){
cout << "sum of first array is less than array 2";
}else{
cout << "sum of first array is greater than array 2";
}


}

No comments:

Post a Comment