#5 | Pointers | Find Maximum Number Using Pointers | #comptech #prathamrathod

  


YouTube Video :- 





Question :- 

Write a Program to Find a Maximum Number using Pointer's

Code :-



#include<stdio.h>

void main()
{
    // declaring Variables
    int a,b;
    int *p,*p1;

    // Initilize Values

    printf("Enter First Number : ");
    scanf("%d",&a);

    printf("\nEnter Second Number : ");
    scanf("%d",&b);

    // assign address of two varriables to the pointer variable

    p = &a;
    p1 = &b;

    if (*p > *p1)
    {
        printf("%d is Maximum ",*p);
    }
    else
    {
        printf("%d is Maximum ",*p1);
    }
}


Description :-

  • In this Program , we have to find a maximum number from two numbers using pointers.
  • First we will declare two integer variables for storing the values.
  • Then we will declare two pointers variable, so that we can store the memory addresses of two variables (Because in our query we have find maximum number using pointer's)
  • For comparing the values, first we have required values. so that we will assign values to the two integer variables.
  • After assigning them the values, we will assign memory addresses to the pointer variables of integer variable.
  • Using memory addresses we will find that which value is stored in That memory locations.
  • Using * (star) sign we will take values from the memory addresses.
  • Then we will compare them using if...else statements.
  • we will give condition that, *p(Value that is stored in memory address p) is greater than *p1(Value that is stored in memory address p1) .
  • if *p is big than it will print the statement that a/*p value is maximum.
  • else it it will print the statement that b/*p1 value is maximum.

! Thank You For Visiting !


Comments

Popular posts from this blog

#9 | Pointer | Write a program to count vowels and consonants in string using pointer

#6 | Pointers | Write a Program to store n Elements in an array and print them using Pointers