Answers for "find max number in c"

1

How to define Max in define in c

// For defining x > y
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
// For defining x < y
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
Posted by: Guest on November-05-2020
6

find maximum number in array

#include <stdio.h>
int main() {
    int i, n;
    float arr[100];
    printf("Enter the number of elements (1 to 100): ");
    scanf("%d", &n);

    for (i = 0; i < n; ++i) {
        printf("Enter number%d: ", i + 1);
        scanf("%f", &arr[i]);
    }

    // storing the largest number to arr[0]
    for (i = 1; i < n; ++i) {
        if (arr[0] < arr[i])
            arr[0] = arr[i];
    }

    printf("Largest element = %.2f", arr[0]);

    return 0;
}
Posted by: Guest on April-28-2020
0

max number in c

#include <stdio.h>
#include <stdlib.h>

int main()
{
    double num1,num2,maxNum,minNum;

    printf("Enter a number: ");
    scanf("%lf", &num1);
    printf("Enter another number: ");
    scanf("%lf", &num2);
    printf("n");

    if (num1 > num2){
        maxNum = num1;
        minNum = num2;
      
        printf("The largest number is %f n",maxNum);
        printf("The smallest number is %f n",minNum);
    }else if (num1 < num2){
        maxNum = num2;
        minNum = num1;
      
        printf("The largest number is %f n",maxNum);
        printf("The smallest number is %f n",minNum);
    }printf("The numbers are equal");

    return 0;
}
Posted by: Guest on June-03-2021
0

max function c

#define new_max(x,y) (((x) >= (y)) ? (x) : (y))
#define new_min(x,y) (((x) <= (y)) ? (x) : (y))
Posted by: Guest on August-13-2021

Browse Popular Code Answers by Language