#include <stdio.h>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
srand(time(NULL));
int sum = 0;
int i;
const int n = 5;
int array[n];
for(i=0;i<n;i++)
array[i] = rand()%100 - 50;
if(array[i] < 0)
sum+=array[i];
}
cout << setw(5) << array[i];
cout << "sum ="<< sum;
return 0;
#include <stdio.h>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
srand(time(NULL));
int sum = 0;
int i;
const int n = 5;
int array[n];
for(i=0;i<n;i++)
{
array[i] = rand()%100 - 50;
if(array[i] < 0)
{
sum+=array[i];
}
cout << setw(5) << array[i];
}
cout << "sum ="<< sum;
return 0;
}