Coding Practice: Write a program in C to find out maximum and minimum number from given four integer numbers using conditional statement if()

in hive-185836 •  3 years ago  (edited)

coding.jpg

Problem: Write a program in C to to find out maximum and minimum number from given four integer numbers using conditional statement if() and display the result on computer screen display


This program demonstrates usage of conditional statement "if else" in C language. Basically this program is for novice learner who are learning now chapter "Overview of C & basic structure of a C program".

So, let's do it --

    /*This program demonstrates how to find out maximum and minimum number from given four integer numbers using conditional statement if() in C language. 
Basically this program is for novice learner who are learning now chapter "Overview of C & basic structure of a C program" */

//Programmed by Phantom

#include <stdio.h> //header file link standard Input & Output (I/O)


int main() //main function
{
    int number1, number2, number3, number4; //local variable declaration
    int maximum, minimum;
    
    // assign values to all integer variables
    number1 = 595; 
    number2 = 643;
    number3 = 1006;
    number4 = 56;
    
    //find out maximum number
    if(number1>number2) 
      {
          maximum = number1;
      }
    else
      {
          maximum = number2;
      }
      
    if(maximum<number3)
      {
          maximum = number3;
      }
      
    if(maximum<number4)
      {
          maximum = number4;
      }
    
    //print the maximum number on the computer screen
    printf("Maximum number is %d in the given numbers %d %d %d %d\n",maximum,number1,number2,number3,number4);
    
    //find out minimum number
    if(number1<number2) 
      {
          minimum = number1;
      }
    else
      {
          minimum = number2;
      }
      
    if(minimum>number3)
      {
          minimum = number3;
      }
      
    if(minimum>number4)
      {
          minimum = number4;
      }
    
    //print the minimum number on the computer screen
    printf("Minimum number is %d in the given numbers %d %d %d %d",minimum,number1,number2,number3,number4);
    
    
    return 0; //program executed successfully
} //End of program


Output

    Maximum number is 1006 in the given numbers 595 643 1006 56
    Minimum number is 56 in the given numbers 595 643 1006 56

Do it yourself on online C compiler: https://www.tutorialspoint.com/compile_c_online.php

Or, download Turbo C++ (ver. 3.0)
Download Turbo C++ for Windows 7, 8, 8.1 and Windows 10 (32-64 bit) with full/window screen mode and many more extra feature

Tomorrow I'll post another C problem with solution.
Have a nice day.
Thank you very much.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thanks @rme for great support to xpilar.witness

Nice that you post in our community

Thank you very much for curating my post. Yes, I love this community & feel happiness to post here :)

hello and welcome to World of xpilar

i could use one of your witness votes . to vote me as a witness simple click the below link and sign the transaction

https://steemlogin.com/sign/account-witness-vote?witness=steem-supporter&approve=1

or you can do that by going to the witness page too

cheers
Together We grow

Hello,
I just upvoted @steem-supporter as witness.

Untitled.png

thanks