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

Please help me answer these two questions Thanks a lot Question 1 You are requir

ID: 3622816 • Letter: P

Question

Please help me answer these two questions
Thanks a lot

Question 1
You are required to develop a program that prompts the user to enter an integer
value (int). The programme should then display the number of bytes used to store
this type of variable.
For the value entered your programme should then display the values of the
individual bytes used to store the value entered.

Question 2
The file ‘data.dat’ provided contains 100 integer values, each on a new line. You
are to develop a programme that reads these values from the file, displays each
value on a new line and then provides details of the minimum, maximum and mean
of the values.

Thanks again !

Explanation / Answer

// Question 1 answer

#include<stdio.h>
#include<conio.h>                   // comment this line if u are using linux
int main()
{
int k,i;
static int p;
printf("enter the value of k :");
scanf("%d",&k);
printf("given integer %d will take %d bytes ",k,sizeof(k));
for(i=sizeof(k); i>0; --i)
{
printf("%d byte contain value %d ",p+1,k &0xff);
k>>=8;
p++;
}
getch();                         // comment this line if u are using linux
return 0;
}

// Question 2 answer

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<conio.h>                        // comment this line if u are using linux
#define IN "data.dat"
int Read_Data(int x[]);
void PRINT_ARRAY(int x[],int size);
void minmaxmean(int x[],int size,int *,int *,double *);
int main()
{
int x[100];
int min,max;
double mean;
int size=Read_Data(x);
clrscr();
PRINT_ARRAY(x,size);
minmaxmean(x,size,&min,&max,&mean);
printf(" minimum = %d maximum = %d mean = %.2lf ",min,max,mean);
getch();                              // comment this line if u are using linux
return(0);
}

int Read_Data(int x[])
{
int l=0;
char s[25];
int a;
FILE *one=fopen(IN,"r");
while(fgets(s,25,one)!=NULL)
{
sscanf(s,"%d",&a);
x[l]=a;
l++;
}
fclose(one);
return l;
}

void PRINT_ARRAY(int x[],int size)
{
int j;
printf(" X ");
for(j=0;j<size;j++)
printf("%d ",x[j]);
}


void minmaxmean(int x[],int size,int *min,int *max,double *mean)
{
int j;
int mn,mx;
double sum;
mn = mx = x[0];

for(j=0;j<size;j++)
{
if(x[j]<mn) mn = x[j];
if(x[j]>mx) mx = x[j];
sum = sum+x[j];
}
*min = mn;
*max = mx;
*mean = sum / size;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote