online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <assert.h> #include <stdio.h> #include <stdlib.h> typedef struct { char all_equal; // true if all numbers were equal int max; // the greatest number } Result; void read_numbers(int *dst, int count); Result find_greatest(int *numbers, int count); void output_result(const Result *r); int main() { enum { N = 3 }; int numbers[N]; read_numbers(numbers, N); const Result r = find_greatest(numbers, N); output_result(&r); } void read_numbers(int *dst, int count) { assert(count > 0); printf("Enter %d numbers.\n", count); for (int i = 0; i < count; /*empty*/) { printf("#%d: ", i+1); int c = scanf("%d", &dst[i]); if (c == EOF) abort(); if (c != 1) { printf("Sorry, invalid input. Try again.\n"); while ((c = getchar()) != EOF && c != '\n'); if (c == EOF) abort(); } else i++; } } Result find_greatest(int *numbers, int count) { assert(count > 0); Result r = {.all_equal = 1, .max = numbers[0]}; for (int i = 1; i < count; i++) { r.all_equal = r.all_equal && numbers[i] == r.max; if (numbers[i] > r.max) r.max = numbers[i]; } return r; } void output_result(const Result *r) { if (r->all_equal) printf("All numbers are equal.\n"); else printf("%d is the greatest among the numbers entered.\n", r->max); }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue