#include int pleaseAdd( int a, int b ) { // define a function before it is calle
ID: 3625659 • Letter: #
Question
#include
int pleaseAdd( int a, int b ) { // define a function before it is called
int c = a + b; // a and b are the function parameters return c;
}
int main( ) {
int x, y; // declare variables before you use them
scanf(“%i %i”, &x, &y); // use the variables
int z = pleaseAdd( x, y ); // call the function
printf(“The sum is %i ”, z);
return 0;
}
2. For this lab, follow the model above and write three functions. The first counts from 0 to the parameter and prints the numbers out in a single line. The second function counts down to 0 from the parameter. The last function should count between the two parameters. If the first number is smaller than the second number, the function should count up. If the first number is larger, the function should count down.
Once all three functions are written, write a main function that prompts the user for two positive numbers then uses the first for the count up and dount down functions and both numbers for the count between function. After doing this once, the program should ask the user if they would like to quit or re-run the program.
Output example :
Explanation / Answer
void up(int x); void down(int y); void middle(int m,int n); void main() { int a,b; int c; do { scanf("%i,%i",&a,&b); up(a); down(b); middle(a,b); printf("Do you want to run it again with two different ints?(Enter 1 for yes, 2 for no)"); }while(c==1); } void up(int x) { for(int i=0;i=0;i--) print("%i",i); }//end of down void middle(int x,int y) { if(x>y) { for(int i=x;i>=y;i--) print("%i",i); } }//end of if else { for(int i=x;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.