-->

program to compare of two numbers using pointer

//comparison of two numbers using pointer     //comment of program
#include <stdio.h>                           //header file
int main()
{
    float *p,*p1;                        //two pointer declaration
    float x,y;                           //variable declaration
    printf("enter two values for x and y\n");//prints message
    scanf("%f%f",&x,&y);                    // gets input
    p=&x,p1=&y;                        //assigning address to that pointer
    printf("the address of x(%f) is=%f\n",x,p);//display of that address
    printf("the address of y(%f) is=%f\n",y,p1);//display of address of second variable
    if(*p>*p1)                              //comparison of two values using pointer
    {
       printf("%f is greater \n",*p);
    }
    else
    {
        printf("%f is greater \n",*p1);
    }

        return 0;
}
----------------------------------------------------------------------------------------------------

using turboc++
---------------------------------------------------------------------------------------------------
//comparison of two numbers using pointer     //comment of program
#include <stdio.h>                           //header file
#include<conio.h>
int main()
{
    float *p,*p1;                        //two pointer declaration
    float x,y;                           //variable declaration
    printf("enter two values for x and y\n");//prints message
    scanf("%f%f",&x,&y);                    // gets input
    p=&x,p1=&y;                        //assigning address to that pointer
    printf("the address of x(%f) is=%f\n",x,p);//display of that address
    printf("the address of y(%f) is=%f\n",y,p1);//display of address of second variable
    if(*p>*p1)                              //comparison of two values using pointer
    {
       printf("%f is greater \n",*p);
    }
    else
    {
        printf("%f is greater \n",*p1);
    }
       getch();
        return 0;
}

No comments:

Post a Comment