includestdioh void myfunction int aint bint cint sumint prodfloat average

Includestdioh void myfunction int aint bint cint

This preview shows page 3 - 5 out of 5 pages.

***************************************************************************/#include<stdio.h>void myfunction(int a,int b,int c,int *sum,int *prod,float *average) // function{ *sum=a+b+c; *prod=a*b*c; *average=(a+b+c)/3.0; }  // end of function int main (void) // main program or main function {int x,y,z,su_m,product;float av_g;printf("Enter three integer input parameters a, b and c :");scanf("%d %d %d",&x,&y,&z);myfunction(x, y, z, &su_m, &product, &av_g);  // function call          printf("*******************************************************");printf("\nThe sum = %d\nThe product = %d\nthe avg = %f\n",su_m,product,av_g);return 0; }  // end of mainExample#3:Write function to take coefficients of quadratic equation  a, b and c as input parameter and return two roots of quadratic equation as output parameters (using pointers). If the discriminant is negative, it should print “no real roots” and terminates the program execution.  Write main program to call this function.  Answer:#include<stdio.h>#include<math.h>#include<stdlib.h>void quadratic(double a,double b, double c, dooble *root1, double *root2)  // user-defined function{double d;d=b*b-4*a*c;if(d < 0){  printf("No real roots\n");Page 3 of 5
Image of page 3
  exit(0); } else { *root1=(-b+sqrt(d))/(2*a); *root2=(-b-sqrt(d))/(2*a); } } void main() { double a,b,c,r1,r2; printf("Please input a, b, c :"); scanf("%lf %lf %lf",&a,&b,&c); quadratic(a,b,c,&r1,&r2); // function call printf("\nThe first root is : %f\n",r1); printf("The second root is : %f\n", r2); } Page 4 of 5
Image of page 4
Example#4: Write a function program  swap  using output parameters to swap the values between 2 integer variables  a  and  b.  The main program should read the two,  integer,  non zero variables by calling a function  readint  using output  parameters . Then the main function calls  swap  function to swap the values. Print the values of variables a and b  in main function , before calling the swap function and after calling swap function. Answer #include<stdio.h> void readint(int *a, int* b); void swap (int *a, int *b); int main () { int num1,num2; readint(&num1,&num2); printf("before swapping num1= %d, num2=%d\n",num1,num2); swap(&num1,&num2); printf("after swapping num1= %d, num2=%d\n",num1,num2); return 0; } void readint (int *a, int *b) { printf("enter first integer number >"); scanf("%d",a); printf("enter second integer number >"); scanf("%d",b); } void swap (int *a, int*b) { int temp; temp=*a; *a=*b; *b=temp; } Page 5 of 5
Image of page 5

You've reached the end of your free preview.

Want to read all 5 pages?

  • Spring '10
  • zaman
  • main program, output parameters

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes