Commit a4c6f3e6 by Tobias Langer

Added functionality.

parent 42d8d51d
#include <stdio.h>
#include <stdlib.h>
#define UNUSED(x) ((void)(x))
int sum(int n)
{
return ((n + 1) * n) / 2;
}
void usage(const char* app_name, const char* err_string)
{
if(err_string != NULL) {
fprintf(stderr, "%s\n", err_string);
}
fprintf(stderr, "Usage: %s <n>\n", app_name);
exit(1);
}
int main(int argc, char* argv[])
{
UNUSED(argc);
UNUSED(argv);
printf("Hallo Welt!\n");
if(argc != 2) {
usage(argv[0], NULL);
return 1;
}
int n = atoi(argv[1]);
if(n <= 0) {
usage(argv[1], "n must be a natural number.");
}
printf("Summe der nat. Zahlen von 1 - %i: %i\n", n, sum(n));
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment