Tuesday, April 15, 2014

Code to find the greatest number from user input


In this we are going to show all beginners how can you detect the greatest digit among multiple numbers.

Step 1:

   #include<stdio.h>
   #include<conio.h>

   void main()
   {
      clrscr();


      getch();
   }

This step is nothing but defining the basic C programming syntax.

Step 2:

   int a,b,c;

In this step we declared 3 variables( variables should be declared above clrscr() ) which will be used to store user inputs.

Step 3:

   printf("Enter any 3 numbers\n");

   scanf("%d%d%d",&a,&b,&c);

In this step we have written the code to accept 3 integer values from users.

Step 4:

   if(a>b && a>c)
   {
      printf("%d is the greatest number\n",a);
   }

   if(b>a && b>c)
   {
      printf("%d is the greatest number\n",b);
   }

   if(c>a && c>b)
   {
      printf("%d is the greatest number\n",c);
   }

This is the main and the final step as it does all the comparing of values entered by the user. As you can see above it is very easy to find the greatest number the only thing we need to do it compare each and every value with the other values to find the greatest. You can download the complete code file and run it from your TURBO C++ software by clicking the below link.

 Download

Yes that's it, we hope that you liked our post if you did link our post with your social networks and do comment.

Happy Programming !

No comments :

Post a Comment