|
Write a program that uses macro PRINTARRAY to print an array of integers. The
macro should receive the array and the number of elements in the array as
arguments.
#include <iostream.h>
#include<iomanip.h>
#define PRINTARRAY( A, N )
for ( int i = 0; i < ( N ); ++i ) \ cout << setw( 3 ) << A[ i ]
#define SIZE 10 i
nt main()
{
int b[ SIZE ] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 };
cout << "The array values are:\n";
PRINTARRAY( b, SIZE );
cout << endl;
return 0;
}
|
|
Write a program in c c++ that uses macro SUMARRAY to sum the values in a numeric
array. The macro should receive the array and the number of elements in the
array as arguments.
#include < iostream.h>
#define SUMMARRAY( A, S ) for ( int c = 0; c < S; ++c ) \ 8 sum += A[ c ];
9 #define SIZE 10 10 11
int main()
{
int array[ SIZE ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, sum = 0;
SUMMARRAY( array, SIZE );
cout << "Sum is " << sum << endl;
return 0;
}
|