answersLogoWhite

0

#include<iostream>

#include<iomanip>

#include<time.h>

void print(int a[], size_t size)

{

using std::cout;

using std::endl;

using std::setw;

for(size_t index=0; index<size; ++index)

cout<<setw(5)<<a[index];

cout<<endl;

}

int main()

{

srand((unsigned)time(NULL));

const size_t size=10;

int a[size], b[size], c[size];

// Initialise a and b with random integers (range 1-99)

for(size_t index=0; index<size; ++index)

{

a[index]=rand()%99+1;

b[index]=rand()%99+1;

}

// Initialise c with products of a and b.

for(size_t index=0; index<size; ++index)

c[index]=a[index]*b[index];

// Calculate sum of c.

int sum=0;

for(size_t index=0; index<size; ++index)

sum+=c[index];

// Print results.

std::cout<<"Array a:\t"; print(a,size);

std::cout<<"Array b:\t"; print(b,size);

std::cout<<"Products:\t"; print(c,size);

std::cout<<"Sum product:\t"<<sum<<std::endl;

}

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

Different types of elements which require storage during program execution?

Variables, arrays, objects, and pointers are common elements that require storage during program execution. Each of these elements holds data that needs to be accessed or modified during the running of the program.


Can element of character arrays be accessed in the same way as the elements of a numeric arrays?

Yes, it can.


Which data structure can't store the non-homogeneous data elements?

arrays


Difference between integer array and character array?

Arrays are basic structures wherein one or more elements exist "side by side" and are of the same "type". An "integer" array is an array whose elements are all of an integer type which has no fractional component. A "character" array is an array which contains nothing but character types. A "floating point" array contains elements that have both an integer and fractional portion. Simply put, they are arrays of particular types.


How do you find repeated integer number in the array in java program?

The most simpliest way is to use a nested loop. However this runs in O(N*N) time. For small arrays, this should be sufficient.


What are matrix questions?

They are questions which deal with rectangular arrays of elements.


How can you make a array with the number 16?

If you mean how do you create an array with 16 elements, there are two ways: int a[16]; /* fixed size array of 16 integer elements */ int* b = malloc(16*sizeof(int)); /* variable length array with (initially) 16 integer elements */ Remember that variable length arrays allocated on the heap must be released as soon as they are no longer required: free (b); b=NULL;


What type of data is acceptable for arrays index?

The details depend on the language, but the index of an array is usually an integer data type. Anything that is compatible with an integer can be used.


How can you do the same thing as the program below but using strings and arrays in C language?

Program below?!


How do you write a programme in c language using arrays to store a ten integer data and find the second smallest and second largest elements in the array?

void mail ( ); { int a, b c = a+b; printf ("%d",=c); }


Which data structure can't store the homogeneous data elements?

arrays


What are matrices made of?

In mathematics matrices are made up of arrays of elements.