Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int nwd(int n,int m)
  6. {
  7. while(n!=m)
  8. {
  9. if(n>m)
  10. {
  11. n=n-m;
  12. }
  13. if(n<m)
  14. {
  15. m=m-n;
  16. }
  17. }
  18. return n;
  19. }
  20.  
  21. int main()
  22. {
  23. int n,m;
  24. do{
  25. cout<<"Podaj liczbe n:"<<endl;
  26. cin>>n;
  27. cout<<"Podaj liczbe m"<<endl;
  28. cin>>m;
  29. }while(n<0 && m<0);
  30.  
  31. cout<<"Zadanie 1:"<<endl;
  32. int i=1;
  33. while(true)
  34. {
  35. if((i*n)>=m)
  36. {
  37. break;
  38. }
  39. if((i*n)<m)
  40. {
  41. cout<<i*n<<" ";
  42. }
  43. i++;
  44. }
  45.  
  46.  
  47.  
  48. cout<<endl<<"Koniec zad1"<<endl;
  49.  
  50. cout<<endl<<"Zadanie 2"<<endl;
  51.  
  52. int asd=nwd(n,m);
  53. cout<<asd;
  54.  
  55. cout<<endl<<"Koniec zad2"<<endl;
  56.  
  57.  
  58. cout<<endl<<"Zadanie 3"<<endl;
  59. int suma=0;
  60. for (int i=1;i<n;i++)
  61. {
  62. if(nwd(i,n)==1)
  63. {
  64. suma+=i;
  65. }
  66. }
  67.  
  68. cout<<endl<<"Suma="<<suma<<endl;
  69. cout<<endl<<"Koniec zad3"<<endl;
  70.  
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement