C program to print smaller of 2 numbers

Solution with out using functions
Solution with out using functions(another method)
Solution with out using functions(Using Conditional Operator)
Solution using functions without passing arguments
Solution using functions and by passing arguments



Solution : Without using function
Program/Source Code

#include <stdio.h>

 int main()
 {
    int a,b;
     printf("Enter 2 nos ");
     scanf("%d %d",&a,&b);
     if(a<b)
         printf("Min no = %d",a);
     else
         printf("Min no = %d",b);
 return 0;
 }

Output:

case :1
Enter 2 nos 25
63
Min no = 25

case :2
Enter 2 nos 14
25
Min no = 14



Solution : Without using function(another method)
Program/Source Code

#include <stdio.h>

 int main()
 {
    int a,b,c;
     printf("Enter 2 nos ");
     scanf("%d %d",&a,&b);
     if(a<b)
        c=a;
     else
        c=b;
    printf("Min no = %d",c);
 return 0;
 }

Output:

 



Solution : Without using function(Using Conditional Operator)
Program/Source Code

#include <stdio.h>

 int main()
 {
    int a,b,c;
     printf("Enter 2 nos ");
     scanf("%d %d",&a,&b);
     c=(a<b)?a:b;
    printf("Min no = %d",c);
 return 0;
 }

Output:

 



Solution : Using function Without Passing Arguments
Program/Source Code

#include <stdio.h>
void check()
{
    int a,b;
     printf("Enter 2 nos ");
     scanf("%d %d",&a,&b);
     if(a<b)
         printf("Min no = %d",a);
     else
         printf("Min no = %d",b);
}

 int main()
 {
    check();
 return 0;
 }

Output:

case :1
Enter 2 nos 425
23
Min no = 23

case :2
Enter 2 nos 141
651
Min no = 141



Solution : Using function Passing Arguments
Program/Source Code

#include <stdio.h>
void check(int a,int b)
{
     if(a<b)
         printf("Min no = %d",a);
     else
         printf("Min no = %d",b);
}

 int main()
 {
     int a,b;
     printf("Enter 2 nos ");
     scanf("%d %d",&a,&b);
    check(a,b);
 return 0;
 }

Output:

case :1
Enter 2 nos 125
63
Min no = 63

case :2
Enter 2 nos 14
251
Min no = 14

Previous:

Next:

C Language Programming Tutorial

C Language Tutorial Home    Introduction to C Language     Tokens     If Condition     goto statement and Labelname     Switch Statements     For loop     While Loop    Do while loop     break and continue    Functions    Recursion    Inbuild Functions    Storage Classes    Preprocessor    Arrays    Pointers     Structures and Unions    File Handling     Projects

Tutorials

Technical Questions

Interview Questions

C Programming
C++ Programming
Class 11 (Python)
Class 12 (Python)
C Language
C++ Programming
Python

C Interview Questions
C++ Interview Questions
C Programs
C++ Programs