#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;
}
Yes, it can.
arrays
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.
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.
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;
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.
Yes, it can.
arrays
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.
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.
They are questions which deal with rectangular arrays of elements.
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;
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.
Program below?!
void mail ( ); { int a, b c = a+b; printf ("%d",=c); }
arrays
In mathematics matrices are made up of arrays of elements.