Advertisement
ULK

Лабораторная №8 (6.23в)

ULK
Nov 30th, 2022
1,080
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n, a, temp;
  8.     int sum = 0;
  9.    
  10.     cout << "Enter the number n: ";
  11.     cin >> n;
  12.    
  13.     cout << "Enter the number a (0<=a<=8): ";
  14.     cin >> a;
  15.    
  16.     while (n>0){
  17.         temp = n%10;
  18.             if (temp>a){
  19.                 sum = sum + temp;
  20.             }
  21.         n = n/10;
  22.     }
  23.    
  24.     cout << "Sum of n's digits greater than a: " << sum ;
  25.    
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement