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

The code is working i just need someone to change it up to make it look differen

ID: 3699212 • Letter: T

Question

The code is working i just need someone to change it up to make it look different

/this is the producer program
//as not specified language of code
//I write this code in c
//save this as Prod64bitOS.c

//after that do the same for the Cons64bitOS.c
//and then compile and run as shown in the output image

//below is the image of two code and the code itself


//Prod64bitOS.c

#include
#include
#include

int main()
{
    int min = 3, max = 7, total = 10;

    // Use current time as seed for random generator
    //for pseudo random number generator
    srand(time(0));

    int i;

    for (i = 0; i < total; i++) {
        int num = rand() % (max -min + 1) + min;
        printf("%d ", num);
    }
    return 0;
}

//SECOND PROGRAM


//Cons64bitOS.c

#include
#include

int main()
{
    //In this program consumer program which reads the
    //pipelined data i.e; data send by the Producer program

    //As the input is read usign the stdin function

    //as we know the numbers is only between 3 and 7
    //so we make a array which stores the number of
    //occurences of particular digit

    //initlialize the hash array with 0 value
    int hash[10]={0};

  

    int num,i;

    printf("Values received:");
    //for reading the data and updating the hash array
    while(scanf("%d",&num)!=EOF){
        printf("%d, ",num );
        hash[(int)num]+=1;
    }


    printf(" -----HISTOGRAM----- ");
    //for printing the output
    for(i=3;i<=7;i++)
    {
        printf("%d: ",i );
        int j=hash[i];
        while(j--){
            printf("*");
        }
        printf(" ");
    }

    printf("END OF RUNNING PROGRAM ");
    return 0;
}

Working

The code is working i just need someone to change it up to make it look different

/this is the producer program
//as not specified language of code
//I write this code in c
//save this as Prod64bitOS.c

//after that do the same for the Cons64bitOS.c
//and then compile and run as shown in the output image

//below is the image of two code and the code itself


//Prod64bitOS.c

#include
#include
#include

int main()
{
    int min = 3, max = 7, total = 10;

    // Use current time as seed for random generator
    //for pseudo random number generator
    srand(time(0));

    int i;

    for (i = 0; i < total; i++) {
        int num = rand() % (max -min + 1) + min;
        printf("%d ", num);
    }
    return 0;
}

//SECOND PROGRAM


//Cons64bitOS.c

#include
#include

int main()
{
    //In this program consumer program which reads the
    //pipelined data i.e; data send by the Producer program

    //As the input is read usign the stdin function

    //as we know the numbers is only between 3 and 7
    //so we make a array which stores the number of
    //occurences of particular digit

    //initlialize the hash array with 0 value
    int hash[10]={0};

  

    int num,i;

    printf("Values received:");
    //for reading the data and updating the hash array
    while(scanf("%d",&num)!=EOF){
        printf("%d, ",num );
        hash[(int)num]+=1;
    }


    printf(" -----HISTOGRAM----- ");
    //for printing the output
    for(i=3;i<=7;i++)
    {
        printf("%d: ",i );
        int j=hash[i];
        while(j--){
            printf("*");
        }
        printf(" ");
    }

    printf("END OF RUNNING PROGRAM ");
    return 0;
}

Working

00 skyhawk 14@skyhawk14-x542uq: Chegg skyhawk_14@skyhawk14-x542uq: /Chegg$ gcc -o Prod64bitos.out Prod64bitos.c skyhawk 14@skyhawk14-x542uq:-/Chegg$ gcc -o Cons64bitos.out Cons64bitos.c skyhawk 14@skyhawk14-x542uq: /Chegg$ /Prod64bitoS.out | ./Cons64bitos.out alues received:4, 4, 6, 5, 3, 3, 3, 5, 5, 6 HISTOGRAM- 3: 5: 6: END OF RUNNING PROGRAM kyhawk 14@skyhawk14-x542uq:-/Chegg$ /Prod64bitoS.out./Cons64bitoS.out alues received:7, 6, 6, 5, 3, 4, 5, 3, 7, 3, HISTOGRAM-. 5: 7: *8 END OF RUNNING PROGRAM skyhawk 14skyhawk14-x542uq:-/cheggs

Explanation / Answer

Changed variable names and comments, and writing way.

Prod64bitOS.c

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

int main()

{

int least = 3, most=7, t=10;

srand(time(0)); // Using current time for pseudo random generator

for (int i = 0; i < t; i++)

{

int number = rand() % (least -most + 1) + least;

printf("%d ", number);

}

return 0;

}

Cons64bitOS.c

#include <stdio.h> //This program reads the data sent by producer program

#include <stdlib.h>

int main()

{

int Array[10]={0}; // A hash table is created to store number of occurence of different digits and initialized to zero

int number;

printf("Given input : ");

  

while(scanf("%d",&number)!=EOF)

{ // Taking values for Array

printf("%d, ",number );

Array[(int)number]+=1;

}

printf("Histogram ");

for(int i=3;i<=7;i++)

{

printf("%d: ",i );

int j=Array[i];

while(j--){

printf("*");

}

printf(" ");

}

printf("Program Ends");

return 0;

}