C - Largest integer among the four inputs Code Example

The code for Largest integer among the four inputs

#include <stdio.h>

int largestNumber(int a, int b, int c, int d);

int main(void) {
  int num1, num2, num3, num4;

  printf("Enter num1: ");
  scanf("%d", &num1);

  printf("Enter num2: ");
  scanf("%d", &num2);

  printf("Enter num3: ");
  scanf("%d", &num3);

  printf("Enter num4: ");
  scanf("%d", &num4);

  int largest = largestNumber(num1, num2, num3, num4);

  printf("Largest integer = %d", largest);

  return 0;
}

int largestNumber(int a, int b, int c, int d) {
  if (!(a < b || a < c || a < d))
    return a;
  else if (!(b < c || b < d))
    return b;
  else if (!(c < d))
    return c;
  else
    return d;
}

/*
Output:
Enter num1: 10   
Enter num2: 12
Enter num3: 5
Enter num4: 7
Largest integer = 12
*/
Code by IncludeHelp, on August 14, 2022 21:32

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.