Advertisement
ValerianBenchea

Cifra de control

Nov 13th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.28 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.    int n, s=0, c;
  7.    cout<<"n="; cin>>n;
  8.    while(n>9)
  9.    {
  10.        s=0;
  11.        while(n!=0)
  12.         {
  13.         c=n%10;
  14.         s=s+c;
  15.         n=n/10;
  16.         }
  17.         n=s;
  18.    }
  19.  
  20.    cout<<s;
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement