mardi 16 février 2021

How can I use a counter controlled loop in C to find the largest number given by a user?

I am working on a homework problem that wants me to write a program in C that will ask the user to enter 6 numbers, and then use a counter controlled loop and if statements to find the largest number. I can only use 3 variables.

I am rather new to C programming and I am stumped on this one. Any help would be appreciated.

#include <stdio.h>

int main(void) {

    int counter;
    int number;
    int largest;

    printf("Enter Number 1:");
    scanf("%d", &largest);

    if ( largest >= 0) {
        printf("%d", "The largest number is:");
    }
}

Aucun commentaire:

Enregistrer un commentaire