C program to print the largest 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("Max no = %d",a);
     else
         printf("Max no = %d",b);
 return 0;
 }

Output:

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

case :2
Enter 2 nos 95
68
Max no = 95



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("Max no = %d",c);
 return 0;
 }

Output:

case :1
Enter 2 nos 45
65
Max no = 65

case :2
Enter 2 nos 35
63
Max no = 63



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("Max no = %d",c);
 return 0;
 }

Output:

case :1
Enter 2 nos 145
65
Max no = 145

case :2
Enter 2 nos 35
163
Max no = 163



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("Max no = %d",a);
     else
         printf("Max no = %d",b);
}

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

Output:

case :1
Enter 2 nos 67
65
Max no = 67

case :2
Enter 2 nos 435
163
Max no = 435



Solution : Using function Passing Arguments
Program/Source Code

#include <stdio.h>
void check(int a,int b)
{
     if(a>b)
         printf("Max no = %d",a);
     else
         printf("Max 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 167
65
Max no = 167

case :2
Enter 2 nos 835
163
Max no = 835

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