1) Write A Program That Displays The Sum of Two Numbers. Apply The Software Development Method? Calculate The Sum of Two Numbers
1) Write A Program That Displays The Sum of Two Numbers. Apply The Software Development Method? Calculate The Sum of Two Numbers
2- Analysis
Problem Input
num1, num2
Problem Output
sum
( sum = num1 + num2)
3- Design / Algorithm
1. Get number 1
2. Get number 2
3. Calculate the sum
4. Display the sum of two numbers
4. Implementation
#include<stdio.h>
Memory: main()
int main(void) num1 num2 sum
{ (int) (int) (int)
int num1, num2; /* input: the two numbers */ 7 10 17
int sum;
return (0);
}
5. Testing 6. Maintenance
2) Function with 1 Argument
Write a function that displays the sum of two numbers?
Note:- we need to declare the function if we write it after the main function
#include<stdio.h> #include<stdio.h>
#include<stdio.h>
int main(void)
{
int num1, num2; /* input: the two numbers */
int sum;
sum = fun_sum(num1,num2);
Memory: fun_sum()
printf("sum = %d\n",sum); num1 num2 sum
(int) (int) (int)
return (0); 10 20 30
}
4) Function with Argument & Return Value
Write two functions. One to calculate the sum of two numbers and the other to display the
result (the sum)?
#include<stdio.h>
sum = fun_sum(num1,num2);
printf("sum = ");
display_result(sum);
return (0);
}
5) Function w/o Argument but Return a Value
Write a function that asks the user to enter two numbers then calculate the sum?
#include<stdio.h>
int fun_sum(void)
{
int num1, num2; /* input: the two numbers */
int sum;
sum = fun_sum();
return (0);
}