Sebastian876

#2601

Oct 8th, 2021
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. #2601
  4.  
  5. Scrieți un program care calculează suma pătratelor cifrelor unui număr
  6. natural de trei cifre citit de la tastatură.
  7.  
  8. *******************************************************************************/
  9.  
  10. #include <iostream>
  11.  
  12. using namespace std;
  13.  
  14. int main()
  15. {
  16.     int n,s,c1,c2,c3;
  17.    
  18.     cout<<"Introduceti numarul de 3 cifre : ";
  19.     cin>>n;
  20.    
  21.     c1=n%10;
  22.     c2=(n/10)%10;
  23.     c3=n/100;
  24.    
  25.     s=(c1*c1)+(c2*c2)+(c3*c3);
  26.    
  27.     cout<<"Suma patratelor cifrelor numarului "<<n<<" este "<<s<<endl;
  28.  
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment