Skip to main content

Program_function_01

Using Function: Finding the maximum of three integers.

/* Fig. 5.4: fig05_04.c
    Finding the maximum of three integers */
 #include <stdio.h>
int maximum( int x, int y, int z ); /* function prototype */

 /* function main begins program execution */
 int main( void )
 {
    int number1; /* first integer */
    int number2; /* second integer */
    int number3; /* third integer */

    printf( "Enter three integers: " );
    scanf( "%d%d%d", &number1, &number2, &number3 );

    /* number1, number2 and number3 are arguments
       to the maximum function call */
    printf( "Maximum is: %d\n",  );
    return 0; /* indicates successful termination */
 } /* end main */

/* Function maximum definition */
/* x, y and z are parameters */
int maximum( int x, int y, int z )
{
   int max = x; /* assume x is largest */

   if ( y > max ) { /* if y is larger than max, assign y to max */
      max = y;
   } /* end if */

if ( z > max ) { /* if z is larger than max, assign z to max */
      max = z;

} /* end if */

   return max; /* max is largest value */
} /* end function maximum */
Output:


Comments

Popular posts from this blog

Program_function_02

Adding two Integer number using Function. /* Adding two Integer number using Function.*/  #include <stdio.h> int sum( int x, int y); /* function prototype */ int sub( int x, int y); int mul( int x, int y); int div( int x, int y);  /* function main begins program execution */  void main( )  {     sum (5,7);     sub (10,5);     mul (10,5);     div (10,5);  } /* end main */ /* Function maximum definition */ /* x, y and z are parameters */ int sum( int x, int y) {     printf ("%d", x+y);     getch(); } /* end function maximum */ int sub( int x, int y) {     printf ("%d", x-y);     getch(); } int mul( int x, int y) {     printf ("%d", x*y);     getch(); } int div( int x, int y) {     printf (...

C Program01 Chap01: Area of Squre

/*Prime.Chapter_01/17 Write a program for Area of Squre*/   //document #include<stdio.h>    //Header file #include<conio.h>   //Header file Preprocessor Directive #define N 10        //Symbolic constant     void main()     //main program starts {     int area;       //variable declaration     area = N*N;     //process stmt      printf("Area of square:\n"); // o/p stmt     printf("%d", area);            // to show the output visible     getch();     return 0; }   // Program ends.