What is the final value of sum in this code int total 5 sum


What is the final value of sum in this code? int total = 5, sum = 0; for (int k = 1; k  1; j = j - l) {sum = sum + total;} sum = sum + 3;}

Solution

Answer:

3)

#include<iostream>
using namespace std;

int countPairsWithDiffK(int arr[], int n, int k)
{
   int sum = 0,total=5;
   for (int k = 0; k <=total; k = k + 1)
   {     
   total=total-1;
       for (int j = total; j > 1; j--)
               sum=sum+total;
   }
total= sum=sum+3;
   return total;
}
int main()
{
   int arr[] = {1, 5, 3, 4, 2};
   int n = sizeof(arr)/sizeof(arr[0]);
   int k = 3;
   cout << \"Count of pairs with given diff is \"
       << countPairsWithDiffK(arr, n, k);
   return 0;
}

OUTPUT:Count of pairs with given diff is 23

 What is the final value of sum in this code? int total = 5, sum = 0; for (int k = 1; k 1; j = j - l) {sum = sum + total;} sum = sum + 3;}SolutionAnswer: 3) #in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site