Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C Programming 1. Create an array of 100 random numbers in the range of 1…999, wr

ID: 3774974 • Letter: C

Question

C Programming

1. Create an array of 100 random numbers in the range of 1…999, write a function for each of the following processes. In building the array, if 3 or 7 evenly divide the random number, store it as a negative number. a. Print the array ten values to a line. Make sure that the values are aligned in rows. b. Return a count of the number of even values c. Return the sum of all values in the array

2. Create a two dimensional array (size 10 X 10). Fill this two dimensional array with the values from the above single dimensional array. Determine the maximum value in each row. Display the two-dimensional array and the maximum of each row.

3. Repeat number 2 above but this time instead of 10 X 10 array, prompt the user for the size of the row and column, allow user to fill in the values and display the array.(Hint: Use pointers and dynamic memory allocation )

Explanation / Answer

Ans:

#include<iostream.h>
#include<stdlib.h>

void print(int a[],int n)
{
   int s=0,e=0,c=0;
   for(int i=0;i<100;i++)
   {
       cout<<a[i]<<" ";
       c++;
       if(c%10==0)
           cout<<endl;
       s=s+a[i];
       if(a[i]%2==0)
           e++;
   }
   cout<<"Count of even numbers="<<e<<endl;
   cout<<"sum of values ="<<s;
}

void max_2d(int a[], int n)
{
   int c=0,i,max, b[10][10],j;
   max=0;
   for(i=0;i<10;i++)
   {
       for(j=0;j<10;j++)
       {
           b[i][j]=a[c];
           c++;
                  
       }
   }

   for(i=0;i<10;i++)
   {
       for(j=0;j<10;j++)
       {
           cout<<b[i][j]<<" ";
                              
       }
       cout<<endl;
   }

   for(i=0;i<10;i++)
   {
       for(j=0;j<10;j++)
       {
           if(b[i][j]>max;
               max=[i][j];      
       }
       cout<<"Maximum value in row is"<<max<<endl;
       max=0

   }
  
}


void main()
{
   int n,a[100],i;

   for(i=0;i<100;i++)
   {
       n=rand()%999+1;
       if(n%3==0 || n%7==0)
           a[i]=-n;
       else
           a[i]=n;
   }
   print(a,100);

   max_2d(a,100);


}