Computer Science, asked by seethasubramaniyam05, 1 year ago

Write a pseudo-code to find the sum of numbers divisible by 4.The pseudo-code must allow the user to accept a number and add it to the sum if it is divisible by 4. It should continue accepting numbers as long as the user wants to provide an input and should display the final sum in python.

Answers

Answered by bhagyashreechowdhury
4

Answer:

Pseudo Code to Provide the sum of entered numbers

Following conditions should be satisfied for the program

  • The number should be provided by the user
  • The provided number should be divisible by 4
  • The program should continue accepting the number as long as the user wants it
  • The program should provide the sum of the entered numbers as output

Explanation:

Pseudo Code :

set our initial SUM to 0

set out initial USER_INPUT_OPTION to TRUE

WHILE user input option is TRUE:

    get the USER_INPUT

    if the USER_INPUT is divisible by 4 then:

          SUM = SUM + USER_INPUT

    else:

          print THE NUMBER IS NOT DIVISIBLE BY 4!!

    get the ASK_USER value as 'Yes' or 'No'

    if ASK_USER is Yes then:

           USER_INPUT_OPTION = TRUE

    else:

           USER_INPUT_OPTION = FALSE

print THE SUM OF THE ENTERED NUMBER IS (SUM)

Answered by Anonymous
3

Answer:

Explanation:

#include <cmath>  

#include <iostream>  

using namespace std;  

// Returns sum of n digit numbers  

// divisible by 'number'  

int totalSumDivisibleByNum(int n, int number)  

{  

 // compute the first and last term  

 int firstnum = pow(10, n - 1);  

 int lastnum = pow(10, n);  

 // sum of number which having  

// n digit and divisible by number  

 int sum = 0;  

 for (int i = firstnum; i < lastnum; i++)  

 if (i % number == 0)  

 sum += i;  

return sum;  

// Driver code  

int main()  

{  

int n = 3, num = 4;  

cout << totalSumDivisibleByNum(n, num) << "\n";  

return 0;  

}

Similar questions