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

use the following functions int check_error(int) void initialize_arrays{int[],in

ID: 3538609 • Letter: U

Question

use the following functions

int check_error(int)

void initialize_arrays{int[],int)

void print_array(int[],int)

int common_numbers(int,int)

int mode(int[],int)

void print_histogram(int,int)

main()

sample output

Enter the size of the first input:0

Invalid input enter the size of the inpput again:-12

Invalid input enter the size of the inpput again:123

Invalid input enter the size of the inpput again:6

Enter the size of the second input:0

Invalid input enter the size of the inpput again:-12

Invalid input enter the size of the inpput again:123

Invalid input enter the size of the inpput again:6

input array 1

6 5 8 8 0 2

input array 2

7 9 0 9 8 5 4

There are 6 common numbers between the two arrays

Mode for the first array is number 8

Mode for the second array is number 8

print histogramm

0: **

1:

2:*

3:

4:*

5:**

6:*

7:*

8:****

array before sorting

6 5 8 8 0 2

array after sorting

0 2 5 6 8 8

Explanation / Answer

#include<stdio.h>
int check_error(int x)
{
    int check=0;
    if(x>0)
    {
           if(x<15)
           {
             check=1;
             }
             else
             {
                 check=0;
             }
    }
    else
    {
        check=0;
}
    return check;
}
void initialize_arrays(int a[],int x)
{
     int i;
printf("enter array values:");
for(i=0;i<x;i++)
{
                 scanf("%d",&a[i]);
}   
}
void print_array(int a[],int x)
{
     int i;
     for(i=0;i<x;i++)
{
                 printf("%d ",a[i]);
}  
}
void print_histogram(int i,int z)
{
     int j;
     printf(" %d :",i);
      for(j=0;j<z;j++)
      {
                      printf("*");
      }
}
int mode(int a[],int x)
{
    int m1;
    m1=a[0];
      int p=0,q=0,i=0,j;
      for(i=0;i<x;i++)
      {
                      p=0;
                      for(j=i+1;j<x;j++)
                      {
                                      if(a[i]==a[j])
                                      {
                                                    p=p+1;
                                      }
                      }
                      if(p>q)
                      {
                             m1=a[i];
                      }
      }
      return m1;
}
int common_numbers(int a[],int b[],int x,int y)
{
    int common=0,i,j;
    for(i=0;i<x;i++)
      {
                      for(j=0;j<y;j++)
                      {
                                      if(a[i]==b[j])
                                      {
                                                    common=common+1;
                                                    j=y;
                                      }
                      }
      }
      for(i=0;i<y;i++)
      {
                      for(j=0;j<x;j++)
                      {
                                      if(b[i]==a[j])
                                      {
                                                    common=common+1;
                                                    j=x;
                                      }
                      }
      }
      return common;
}
main()
{
      int x,y,common=0,i,j,m1,m2;
      int check=0;
      printf("Enter the size of the first input:");
      scanf("%d",&x);
      do
      {
      check=check_error(x);
      if(check==0)
      {
                  printf("Invalid input enter the size of the inpput again:");
                  scanf("%d",&x);
      }
      }while(check==0);
      check=0;
      printf("Enter the size of the second input:");
      scanf("%d",&y);
      do
      {
      check=check_error(y);
      if(check==0)
      {
                  printf("Invalid input enter the size of the inpput again:");
                  scanf("%d",&y);
      }
      }while(check==0);
      int a[x],b[y];
      initialize_arrays(a,x);
      initialize_arrays(b,y);
      printf(" input array 1 ");
      print_array(a,x);
      printf(" input array 2 ");
      print_array(b,y);
      common=common_numbers(a,b,x,y);
      printf(" There are %d common numbers between the two arrays ",common);
      m1=mode(a,x);
      printf("Mode for the first array is number %d ",m1);
      m2=mode(b,y);
       printf("Mode for the second array is number %d ",m2);
      printf(" print histogram ");
      int max=a[0],z=0;
      for(i=0;i<x;i++)
      {
                      if(max<a[i])
                      {
                                  max=a[i];
                      }
      }
      for(i=0;i<y;i++)
      {
                      if(max<b[i])
                      {
                                  max=b[i];
                      }
      }
      for(i=0;i<max;i++)
      {
                        z=0;
         for(j=0;j<x;j++)
         {
           if(i==a[j])
           {
                  z=z+1;
           }            
         }
         for(j=0;j<y;j++)
         {
            if(i==b[j])
             {
                  z=z+1;
             }                
         }
      print_histogram(i,z);
      printf(" ");
      }
      int s;
      printf(" array 1 before sorting ");
      for(i=0;i<x;i++)
{
                 printf("%d ",a[i]);
}  
      for(i=0;i<x;i++)
      {
                      for(j=i+1;j<x;j++)
                      {
                          if(a[i]>a[j])
                          {
                                       s=a[i];
                                       a[i]=a[j];
                                       a[j]=s;
                          }             
                      }
      }
      printf(" array 1 after sorting ");
      for(i=0;i<x;i++)
{
                 printf("%d ",a[i]);
}  
printf(" array 2 before sorting ");
      for(i=0;i<y;i++)
{
                 printf("%d ",b[i]);
}  
      for(i=0;i<y;i++)
      {
                      for(j=i+1;j<y;j++)
                      {
                          if(b[i]>b[j])
                          {
                                       s=b[i];
                                       b[i]=b[j];
                                       b[j]=s;
                          }             
                      }
      }
      printf(" array 2 after sorting ");
      for(i=0;i<y;i++)
{
                 printf("%d ",b[i]);
}  
      system("pause");
}