Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<time.h>
- #include<stdlib.h>
- using namespace std;
- int main()
- {
- int x;
- cout<<"Enter lenght of array: ";
- cin>>x;
- srand(time(0));
- int tab[x];
- for(int v=0;v<x;v++)
- {
- tab[x]=rand()%10;
- }
- for(int v=0;v<x;v++)
- {
- cout<<tab[v]<<" ";
- }
- int sum = 0;
- for(int i = 0; i < x; i++){
- sum =sum+tab[i];
- }
- cout<<"Sum of all elements is="<<sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement