Write a small program that calculates the sum and the difference of two integers
ID: 3558933 • Letter: W
Question
Write a small program that calculates the sum and the difference of two integers received from user input with three user-defined functions:
//takes two integer arguments and returns the sum of the two arguments
int CalculateSum (int num1, int num2);
//takes two integer arguments and returns the difference of the two arguments
int CalculateDifference(int num1, int num2);
//takes two integer arguments and two integer pointer arguments
//1. calculate the sum and stores the result in sumptr
//2. calculate the difference and store the result in diffPtr
void CalculateBoth(int num1, int num2, int*sumPtr, int *diffPtr);
Call all three functions from main.
Print the results in both the function definitions (value at) and back in main.
No Calculations should be done in main.
this is the first part of my answer so i have some problems for the rest can u help me please
#include<stdio.h>
int CalculateSum(int num1,int num2);
int CalculateDifference(int num1,int num2);
int main()
{
int result1,result2;
int a=7, b=5;
result1= CalculateSum(a,b);
printf("The sum of the two integers is: %d ",result1);
result2= CalculateDifference(a,b);
printf("The difference of the two integers is: %d ",result2);
}
int CalculateSum(int num1,int num2)
{
int a=7,b=5;
int result1= a+b;
return result1;
}
int CalculateDifference(int num1,int num2)
{
int a=7, b=5;
int result2=a-b;
return result2;
}
Explanation / Answer
#include<stdio.h>
int CalculateSum(int num1,int num2);
int CalculateDifference(int num1,int num2);
void CalculateBoth(int num1, int num2, int *sumPtr, int *diffPtr);
int main()
{
int result1,result2,result3;
int a=7, b=5;
int *sPt,*dPt;
result1= CalculateSum(a,b);
printf("The sum of the two integers is: %d ",result1);
result2= CalculateDifference(a,b);
printf("The difference of the two integers is: %d ",result2);
CalculateBoth(a,b,sPt,dPt);
printf("The sum and difference of the two integers is: %d and %d respectively ",*sPt,*dPt);
return 0;
}
int CalculateSum(int num1,int num2)
{
return num1+num2;
}
int CalculateDifference(int num1,int num2)
{
return num1-num2;
}
void CalculateBoth(int num1, int num2, int *sumPtr, int *diffPtr){
*sumPtr=CalculateSum(num1,num2);
*diffPtr=CalculateDifference(num1,num2);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.