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

Lab 6 (this is to be turned in) You will write a main that declares an array of

ID: 3721908 • Letter: L

Question

Lab 6 (this is to be turned in) You will write a main that declares an array of size 100. In the main you will call three functions. They are int void size): double compAve(int aRI, int size); readData(int aRI I): compDigitSums (int aRI I, int The first function readData is such that using a while loop will read integers from the keyboard and store them in the array aR (that is passed to the function). The while loop will be controlled by an identifier called flag. Our goal is to limit ourselves to two digit integers. The loop will be controlled by an integer identifier called flag which is initialized to be 1. While the flag is one we do the following Read a character For each read, which is performed by scanf, we will check to see if an integer was read. If an integer is not read then we will break out of the loop «If the integer read is > 00 then we set theflag to 0 and do not insert the integer in the array If the integer is negative then we will skip the data and so we do not insert the integer in the array, but do continue the loop Remember to count the number of integers assigned to the array and return this to the main See the lab instructor's outline/pseudo code. Once we have exited the while loop we will return the number of integers assigned to the array to main In the second function compDigitSums We will compute the sum of digits based on their column position of the passed array. So we will have a total of tens and a total of ones (see below). 47 98

Explanation / Answer

// ---------------if you have any doubt feel free to comment below n i will solve is ASAP------------

//-----------and plzzz dont ferget to THUMBS UP :)------------------

//-------------below is the code in c-----------

#include <stdio.h>

#include<stdlib.h>

int readData(int aR[])

{

int flag=0,count=0,i;

int inp;

printf("Enter data ");

while(flag!=1)

{

//here for first if condition i assume that you want to check wether input is integer or not

//for example suppose if input is 23.12 it will break while look

//if this is not what you want first condition for reading integer then plz leave comment below . i will reply ASAP

if (scanf("%d", &inp) == 1)

{

if(inp<100 && inp>=0)

{aR[count++]=inp;

}

else if(inp>99)

flag=1;

//when value is less than 0 we are skipping integer so its better to not use if or else condition for it

}

else

{ count--;

break;

}

}

  

return count;

}

void compDigitSum(int aR[],int size)

{

int sumone=0,sumten=0,i;

for(i=0;i<size;i++)

{

sumone=sumone+(aR[i]%10);

sumten=sumten+(aR[i]/10);

}

printf("Sum of ones is %d ",sumone);

printf("Sum of ones is %d ",sumten);

}

double compAve(int aR[],int size)

{

int i,sum=0;

float ave=0.0;

for(i=0;i<size;i++)

{

sum=sum+aR[i];

}

printf("sum == %f, size== %d ",(float)sum,size);

ave=(float)sum/size;

return ave;

}

int main()

{

int aR[100];

//printf("Hello, World! ");

int size=readData(aR);

printf(" size = %d ",size);

compDigitSum(aR,size);

double ave=compAve(aR,size);

// i didnt get what is mean by display value of average in formatted manners so I just directly displyed it

printf("Average of numbers if array = %f",ave);

  

return 0;

}