Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions exercises/sum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Write a program that takes as input two numbers and print the sum.

Output:
Insert the first number: 1
Insert the second number: 2
Sum: 3
*/

#include <stdio.h>
#include <stdlib.h>

int read(const char *prompt) {
int num;
printf("%s", prompt);
scanf("%d", &num);
return num;
}

int sum(int a, int b) {
return a + b;
}

void print_result(int num1, int num2, int result) {
printf("Sum: %d\n", result);
}

int main() {
int x;
int y;

x = read("Insert the first number: ");
y = read("Insert the second number: ");
print_result(x, y, sum(x,y));

return EXIT_SUCCESS;
}