Advertisement
Guest User

Untitled

a guest
May 26th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #include<iostream>
  2. #include<time.h>
  3. #include<stdlib.h>
  4. using namespace std;
  5. int main()
  6. {
  7. int x;
  8. cout<<"Enter lenght of array: ";
  9. cin>>x;
  10. srand(time(0));
  11. int tab[x];
  12. for(int v=0;v<x;v++)
  13. {
  14.  
  15. tab[x]=rand()%10;
  16.  
  17. }
  18.  
  19. for(int v=0;v<x;v++)
  20. {
  21. cout<<tab[v]<<" ";
  22. }
  23.  
  24. int sum = 0;
  25. for(int i = 0; i < x; i++){
  26. sum =sum+tab[i];
  27.  
  28. }
  29.  
  30. cout<<"Sum of all elements is="<<sum;
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement