Statement:
Find the Maximum & Minimum between Two Numbers.
Algorithm:
Step-1: Read a
Step-2: Read b
Step-3: if (a>b)
Step-4: print maximum=a & minimum=b
Step-5: else, print maximum=b & minimum=a
Step-6: print maximum=b & minimum=a
Step-7: End
Program Listing:
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b ,max, min;
clrscr();
printf("Please Enter Two Numbers");
scanf("%d%d", &a, &b);
if(a>b)
{
max=a;
min=b;
}
else
{
max=b;
min=a;
}
printf("\n\n Max=%d Min=%d", max, min);
getch();
}
• Output:
Please Enter Two Numbers 56
42
Max=56 Min=42
Discussion:
I. It works properly.
II. It can be made for more than 10 numbers.
III. Since we use short signed int so it works within the number range -32768 to +32767
IV. If we use long int then it works within the number range -2147483648 to +2147483647
Find the Maximum & Minimum between Two Numbers.
Algorithm:
Step-1: Read a
Step-2: Read b
Step-3: if (a>b)
Step-4: print maximum=a & minimum=b
Step-5: else, print maximum=b & minimum=a
Step-6: print maximum=b & minimum=a
Step-7: End
Program Listing:
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b ,max, min;
clrscr();
printf("Please Enter Two Numbers");
scanf("%d%d", &a, &b);
if(a>b)
{
max=a;
min=b;
}
else
{
max=b;
min=a;
}
printf("\n\n Max=%d Min=%d", max, min);
getch();
}
• Output:
Please Enter Two Numbers 56
42
Max=56 Min=42
Discussion:
I. It works properly.
II. It can be made for more than 10 numbers.
III. Since we use short signed int so it works within the number range -32768 to +32767
IV. If we use long int then it works within the number range -2147483648 to +2147483647
No comments:
Post a Comment