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

  1. Start 
  2. Read a number to be compare as n1 ,n2 or n3.
  3. 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 <stdio.h>
#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
C program find to the  largest   three number  using pointer

Comments

Popular posts from this blog

Create a structure TIME with members hours, minutes and seconds. Write a C program to add two time objects by passing structure variables to function and display result in H: M: S format.

Create a structure named company which has name, address, phone and no of Employee as member variables. Read name of company, its address, phone and no of Employee. Finally display these members’ value.

Write a c program to check a voting AGE condition using if-else