Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. srand(time(NULL));
  8.  
  9. int tab[5];
  10. int x, suma_cyfr, reszta;
  11.  
  12. suma_cyfr=0;
  13.  
  14. cin>>x;
  15.  
  16. for(int i=0;i<5;i++)
  17. {
  18. tab[i]=(std::rand()%12)+1;
  19. }
  20.  
  21. cout<<endl<<tab[0]<<endl<<tab[1]<<endl<<tab[2]<<endl<<tab[3]<<endl<<tab[4]<<endl;
  22.  
  23. for(int i=0; i<5; i++)
  24. {
  25. if(tab[i]==x)
  26. {
  27. cout<<"Liczba jest w tablicy, jej indeks to"<<i+1;
  28.  
  29.  
  30. while(x!=0)
  31. {
  32. reszta=x%10;
  33. x=x/10;
  34. suma_cyfr+=reszta;
  35. cout<<"Jej suma cyfr to:"<<suma_cyfr<<endl;
  36.  
  37. }
  38.  
  39. }
  40. }
  41. cout<<"Liczby nie ma w tablicy";
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement