Write a program named Problem_7.c that: 1. calls a function named MyPointerAddfu
ID: 2249979 • Letter: W
Question
Write a program named Problem_7.c that:
1. calls a function named MyPointerAddfun.c and passes three integer pointers as given in the prototype: void MyFunWithPointer(int *x, int *y, int *z)
2. The function changes the values of the variables x, y and z (in memory) as below: x = x+y+z y = 1 if x+y+z>11, otherwise y =0 z = largest of x, y and z. Note each operation above is done independent of other operations.
3. Finally the updated values of x, y and z are printed to output.txt as below x y z
4. Use a header file ProblemHeader_7.h to declare/prototype the function.
Explanation / Answer
ProblemHeader_7.h //Definition of ProblemHeader_7.h
int MyPointerAddfun(int a,int b,int c) //definition of MyPointerAddfun.c
{
return(a+b+c);
}
void MyFunWithPointer(int *x,int *y, int *z) //definition of MyFunWithPointer function
{
int sum=MyPointerAddfun(*x,*y,*z); //calling MyPointerAddfun
if(sum>11)
{*x=*x+*y+*z;
*y=1;
}
else
{if(*x>*y)
{if(*x>*z)
*z=*x;
else
*z=*z;}
else if(*y>*z)
*z=*y;
else *z=*z;
}
FILE *f = fopen("output.txt", "w"); //Writing to output.txt
if (f == NULL)
{
printf("Error opening file! ");
exit(1);
}
fprintf(f, "%d %d %d",*x,*y,*z );
fclose(f);
}____________________________________________________________________________________________
Problem_7.c //code for problem_7.c
#include<ProblemHeader_7.h> //including header ProblemHeader_7.h
#include<stdio.h>
void main()
{
int p,q,r;
scanf("%d%d%d",&p,&q,&r); //Input three values
MyFunWithPointer(&p,&q,&r); //calling MyFunWithPointer function
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.