# C program to print the largest of 2 numbers

### 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;
}
```

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

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

## Previous: Next:

### 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

Important Pages