Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Lehre
/
PIN3_test
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a4c6f3e6
authored
Nov 06, 2016
by
Tobias Langer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added functionality.
parent
42d8d51d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
3 deletions
+27
-3
test.c
+27
-3
No files found.
test.c
View file @
a4c6f3e6
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#define UNUSED(x) ((void)(x))
#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
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
UNUSED
(
argc
);
if
(
argc
!=
2
)
{
UNUSED
(
argv
);
usage
(
argv
[
0
],
NULL
);
printf
(
"Hallo Welt!
\n
"
);
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
;
return
0
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment