can i get a c code -S M Fwd: EGR 106 Exam Review Class 27: Review-EGR 106 Assign
ID: 3710659 • Letter: C
Question
can i get a c code
-S M Fwd: EGR 106 Exam Review Class 27: Review-EGR 106 Assignment13B-Exam Desmos l Graphing Calculat e l Need A C Code But ls The + v ? ????https:// bbcswebdav/pid-5181734-dt-content-rid-44033889_1/courses/GVEGR106.03.201820/A 01389620. EGR 105 Fall 16 Ieput file: data.txt 012343673901234367890 Sample output original Data List ..> 0 1 2 3 4 5 6 7 ? 9 0 1 2 3 5 7 90 Flipped Daba umber of seron in original arra7 umber of ones in original array OUTLINE OF THE SOURCE CODE: Anolude other headex files that zou need goid display (ant data Max3incsie) ins nain (roid //totalcount resurn the nunber of sexos and ones found in the aExay //coda eor PART ? ge.. hare, epen ‘ r"ad the fil. Include ALL·rror chack. Diaplay the array //Call Eunesion to ?¢vezze dasa Display sheray //Call funet.se to cours O and i ' //pr nt nunb.r of 0. (nunz.ron) and 2" ?numDn. . ) found in array- print în nais. //Prin?to a2 Evunber (totalcoun5) of 05 nd 2? found in the ar y. This valge nust be returned troN the funetion counterosOnesPrint in nain rsturn 0 f Code fox PART 2 goes here / Code for PART 3 go here //Ceds for DART ? gos kersExplanation / Answer
PROGRAM
#include<stdio.h>
#define MAX 100 // define constant MAX value 100
// Declare prototypes of functions
void reverse(int data[MAX],int size);
int countZerosOnes(int data[MAX],int size,int *pNumZeros,int *pNumOnes);
void display(int data[MAX],int size);
int main()
{
FILE *fp; // Declare File Pointer fp
// Declare interger and one character variables
int size=0,numZeros,numOnes,totalcount;
int data[MAX];
char ch;
int i,count=0;
fp=fopen("f:\data.txt","r"); // open file in read mode
if(fp==NULL) // check condition file exist or not
{
printf(" Error: File can't open for reading ");
}
while(1) // create infinity loop
{
ch=fgetc(fp); // read each character value from file
if(ch==EOF) break; // check condition until end of file then terminate from while loop
fscanf(fp,"%d",&data[i++]); // read values from the text file
size++; // count number of values in the text file
}
printf(" Original Data: ");
display(data,size+1); // calling display() function
printf(" Flipped Data: ");
reverse(data,size+1); // calling reverse() function
printf(" ");
totalcount=countZerosOnes(data,size+1,&numZeros,&numOnes); // calling countZerosOnes() function and receive result totalcount
printf(" Total count of ones & zeros = %d",totalcount);
return 0;
}
// implement reverse() function
void reverse(int data[MAX],int size)
{
int i;
printf(" List ==>");
for(i=size-1;i>=0;i--) // create for loop from length of array to 0
printf("%d ",data[i]); // display array in reverse order
}
// implement countZerosOnes() function
int countZerosOnes(int data[MAX],int size,int *pNumZeros,int *pNumOnes)
{
// declare integer variables and initialze z=0 and o=0 for count zeros and ones
int i,count;
int z=0,o=0;
for(i=0;i<size;i++) // create for loop until size of an array
{
if(data[i]==0){ // check an array contains 0's then count zeros "z"
z++;
}
if(data[i]==1){ //check an array contains 1's then count ones 'o'
o++;
}
}
pNumZeros=&z; // assign an address of z value to pNumZeros
pNumOnes=&o; // assign an address of o value to pNumOnes
printf(" Number of zeros in Original array = %d",*pNumZeros); // display number of zeros
printf(" Number of ones in Original array = %d",*pNumOnes); // display number of ones
count=*pNumZeros+*pNumOnes; // calculate total zeros and ones and assign count
return count; // return count value
}
// implement display() function
void display(int data[MAX],int size)
{
int i;
printf(" List ==>");
for(i=0;i<size;i++) // create for loop until size of an array
printf("%d ",data[i]); // display array elements
}
OUTPUT
Original Data:
List ==>0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
Flipped Data:
List ==>0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
Number of zeros in Original array = 3
Number of ones in Original array = 2
Total count of ones & zeros = 5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.