C Language Tutorial Home

# Function Examples(No Pass and No Return) Set 3

Question:8
Write a function in C language for the following:
1. Max of 3 nos
2. Min of 3 nos
3. Table of a no
4. Exit
Sol:

```#include <stdio.h>

void max()
{
int a,b,c,m;
printf("Enter 3 nos ");
scanf("%d %d %d",&a,&b,&c);
if(a>b && a>c)
m=a;
else
if(b>c)
m=b;
else
m=c;
printf("Max no = %d\n",m);
}
void min()
{
int a,b,c,m;
printf("Enter 3 nos ");
scanf("%d %d %d",&a,&b,&c);
if(a<b && a<c)
m=a;
else
if(b<c)
m=b;
else
m=c;
printf("Min no  = %d\n",m);
}
void table()
{
int n,i,t;
printf("Enter any no ");
scanf("%d",&n);
for(i=1;i<=10;i++)
{
t=n*i;
printf("%d * %d = %d\n",n,i,t);
}
}
int main()
{
int op=0;
while(op!=4)
{
printf("1. Max of 3 nos\n");
printf("2. Min of 3 nos\n");
printf("3. Table of a no\n");
printf("4. Exit\n");
scanf("%d",&op);
switch(op)
{
case 1:
max();
break;
case 2:
min();
break;
case 3:
table();
break;
case 4:
printf("End");
break;
default:
printf("Invalid choice\n");
break;
}
getch();
}
return 0;
}
```

Important Pages