Pages

Wednesday, December 11, 2024

HackerRank - C Language Course

HackerRank - Resources for 

C Language Practice


~ Functions in C Language:- 

1. Function to Find Maximum of Four Integers in C.

- Picks the greatest number from integers a , b , c or d.
- Max Integer will be displayed on the screen with this coding.

#include <stdio.h>

// Function to find the maximum of four integers

int max_of_four(int a, int b, int c, int d)
{
    // Assume A = Max value
    int max = a;

    if (b > max) {
        max = b; // Update max if b is greater
    }
    if (c > max) {
        max = c; // Update max if c is greater
    }
   
    if (d > max) {
        max = d; // Update max if d is greater
    }
   
    return max; // Return the max value
}

int main() {
 
    int a, b, c, d; // Input four integers
    scanf("%d %d %d %d", &a, &b, &c, &d);

    int ans = max_of_four(a, b, c, d); // Get the maximum value

    printf("%d", ans); // Display the result
   
    return 0;
}

No comments:

Post a Comment

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...