Find out Greatest and Smallest number using function

-- Leave a Comment
Hello Here is a c program to find out the largest and the smallest numbers from 3 numbers reading those numbers from users.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<stdio.h>
#include<conio.h>
int gre(int,int,int);
int sma(int,int,int);
void main()
 {
    int a,b,c,g,s;
      printf("Enter 3 numbers:- \n");
      scanf("%d %d %d", &a, &b, &c);
      g=gre(a,b,c);
      s=sma(a,b,c);
      printf("%d is Greatest and %d is Smallest among %d, %d and %d",g,s,a,b,c);
      getche();
   }
int gre(int x,int y, int z)
 {
    int g;
      if(x>y)
       {
          if(x>z)
             g=x;
            else
             g=z;
         }
      else
       {
           if(y>z)
             g=y;
            else
             g=z;
         }
      return (g);
   }
int sma(int x,int y, int z)
 {
    int s;
      if(x<y)
       {
          if(x<z)
             s=x;
            else
             s=z;
         }
      else
       {
           if(y<z)
             s=y;
            else
             s=z;
         }
      return (s);
   }

Here we create two functions for finding smallest and greatest.

Hello This is Sagar Devkota. Studying Bachelor of Software Engineering at Pokhara University, NCIT. Open Source Enthusiastic.

0 comments:

Post a Comment