Untitled

 avatar
unknown
plain_text
a month ago
759 B
2
Indexable
#include <stdio.h>

int main() {
    int n, i, num, max;

    // Input the number of elements
    printf("Enter the number of elements: ");
    scanf("%d", &n);

    if (n <= 0) {
        printf("Please enter a positive number of elements.\n");
        return 1;
    }

    // Input the first number and assume it's the maximum
    printf("Enter number 1: ");
    scanf("%d", &num);
    max = num;

    // Loop to input the remaining numbers and find the maximum
    for (i = 2; i <= n; i++) {
        printf("Enter number %d: ", i);
        scanf("%d", &num);

        if (num > max) {
            max = num;
        }
    }

    // Output the maximum number
    printf("The maximum number is: %d\n", max);

    return 0;
}
Leave a Comment