C program find to the largest three number using pointer
C program find to the largest three number using pointer
In this program i have three integers n1,n2 or n3 . i assigned the address of three to three pointer p1 ,p2 or p3. Now i started the comparison on the value stored at the address pointer.
Algoritham
- Start
- Read a number to be compare as n1 ,n2 or n3.
- check if n1 is largest then n2.
- if condition is true , then check if n1 is largest than n3.
- if condition is true , then print largest number is n1.
- if condition is false, then print largest number is n3.
4. If condition is false , then check if n2 is largest than n3
a . If condition is true , then print n2 is largest number .
b. If condition is false , than print n3 is largest number.
5. End.
PROGRAM
#include <stdlib.h>
int main(int argc, char** argv)
{
int n1, n2,n3;
int *p1, *p2, *p3;
printf("enter first number: ");
scanf("%d",&n1);
printf("enter second number: ");
scanf("%d",&n2);
printf("enter third number: ");
scanf("%d",&n3);
p1 = &n1;
p2 = &n2;
p3 = &n3;
if(*p1> *p2)
{
if(*p1 > *p3)
{
printf("%d is the largest number", *p1);
}
else
{
printf("%d is the largest number", *p3);
}
}
else
{
if(*p2 >*p3)
{
printf("%d is the largest number", *p2);
}
else
{
printf("%d is the largest number", *p3);
}
}
return (EXIT_SUCCESS);
}
OUTPUT
Comments
Post a Comment