w3resource logo
C Programming Exercises

C Exercises: Find the maximum number between two numbers

C Pointer : Exercise-6 with Solution

Write a program in C to find the maximum number between two numbers using a pointer.

Sample Solution:

C Code:

#include <stdio.h>
#include <stdlib.h>
void main()
{
 int fno,sno,*ptr1=&fno,*ptr2=&sno;
 
   printf("\n\n Pointer : Find the maximum number between two numbers :\n"); 
   printf("------------------------------------------------------------\n");   
 
   printf(" Input the first number : ");
   scanf("%d", ptr1);
   printf(" Input the second  number : ");
   scanf("%d", ptr2); 


 if(*ptr1>*ptr2)
 {
  printf("\n\n %d is the maximum number.\n\n",*ptr1);
 }
 else
 {
  printf("\n\n %d is the maximum number.\n\n",*ptr2);
 }

}

Sample Output:

 Pointer : Find the maximum number between two numbers :                                                      
------------------------------------------------------------                                                  
 Input the first number : 5                                                                                   
 Input the second  number : 6                                                                                 
                                                                                                          
 6 is the maximum number. 

Flowchart:

Flowchart: Find the maximum number between two numbers

C Programming Code Editor:

Improve this sample solution and post your code through Disqus.