Question


2) Write a program in C/C++ that asks the user to enter a number then the users input value is passed to a function which in

2) Write a program in C/C++ that asks the user to enter a number then the user's input value is passed to a function which increments the number by 10 and returns the result of the incrementation. Write the program to accomplish the increment using three (3) different techniques. To test each technique separately, the user should enter a different number for each of the three (3) techniques. Make sure that you compile and execute your program. Finally, provide screenshots of your full program and screenshot of your program execution from the integrated development environment you used to write, compile, and execute your program. Please make sure your screenshots are easily and clearly readable. 

0 0
Add a comment Improve this question Transcribed image text
Answer #2

CODE TO COPY:

#include <stdio.h>

// Increment Function 1
int incrm1(int n){
// simply returning number adding 10 to it
return n+10;
}

// Increment Function 2
int incrm2(int n){
// Using Add AND assignment operator
n += 10;
return n;
}

// Increment Function 3
int incrm3(int n){
// Using for loop and Increment operator ++
for(int i=1; i<=10; i++){
n++;
}
return n;
}

int main()
{
int n1, n2, n3;
// Taking input from user for Increment Function 1
printf("Enter the number 1: ");
scanf("%d", &n1);
  
// Calling Increment Function 1 and printing result
printf("Output of Increment Function 1: %d", incrm1(n1));
  
// Taking input from user for Increment Function 2
printf("\nEnter the number 2: ");
scanf("%d", &n2);
  
// Calling Increment Function 2 and printing result
printf("Output of Increment Function 2: %d", incrm2(n2));
  
// Taking input from user for Increment Function 3
printf("\nEnter the number 3: ");
scanf("%d", &n3);
  
// Calling Increment Function 3 and printing result
printf("Output of Increment Function 3: %d", incrm3(n3));

return 0;
}

SNAPSHOTS OF PROGRAM:

#include <stdio.h> // Increment Function 1 int incrm1(int n){ // simply returning number adding 10 to it return n+10; } // Inint main() { int n1, n2, n3; // Taking input from user for Increment Function 1 printf(Enter the number 1: ); scanf(%d, &SAMPLE OUTPUT:

Enter the number 1: 10 Output of Increment Function 1: 20 Enter the number 23 20 Output of Increment Function 2: 30 Enter the

Add a comment
Know the answer?
Add Answer to:
2) Write a program in C/C++ that asks the user to enter a number then the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that asks a user to enter a number to echo it out For...

    Write a program that asks a user to enter a number to echo it out For example : Enter a number : "write the number here" You entered : "the number you wrote up their^ Also make sure to write comments, Use the MIPS assembly language

  • Write a C program that asks the user to enter two real numbers. Then your program...

    Write a C program that asks the user to enter two real numbers. Then your program displays a menu that asks the user to choose what arithmetic operation to be done on those numbers. Depending on the user's entry, the program should display the result to the screen. The sample runs below show what should be done to the numbers entered by the user. Your program should run exactly like shown in the sample runs. make your code run as...

  • Write a program which asks the user to enter an integer. Use switch statement to write...

    Write a program which asks the user to enter an integer. Use switch statement to write out the numeric word (such as ONE) if the user's input is 1; (see the sample run output for the usr input 2 or 3); otherwise, write OUT OF RANGE. Below are few sample runs: If the user enters a 1, the program will print: ONE TWO THREE Or, if the user enters a 2, the program will print: TWO THREE Or, if the...

  • Project 1, Program Design 1. Write a C program replace.c that asks the user to enter...

    Project 1, Program Design 1. Write a C program replace.c that asks the user to enter a three-digit integer and then replace each digit by the sum of that digit plus 6 modulus 10. If the integer entered is less than 100 or greater than 999, output an error message and abort the program. A sample input/output: Enter a three-digit number: 928 Output: 584 2. Write a C program convert.c that displays menus for converting length and calculates the result....

  • complete a program so that it asks the user to enter a number and then prints...

    complete a program so that it asks the user to enter a number and then prints out the user's number, 2x the user's number, and 10x the user's number

  • Write a program using M.I.P.S that asks user “how many positive number that is devisable by...

    Write a program using M.I.P.S that asks user “how many positive number that is devisable by 6 you want to add?” .Then your loopcounter would be the user input. If the user enters a positive number between 1 and 100 that is devisable by 6, you increment your loop counter and add it to the sum.. You need to decide if the positive number entered by the user is divisible by 6 or not. Your program should print an error...

  • C++ programming write a program that asks a user to enter a random IP number (IP...

    C++ programming write a program that asks a user to enter a random IP number (IP number is nothing but 4 numbers with dots in between and each number is between 0 and 255) (example: 1.2.3.4 or 255.255.255.255) The program you will write (Write the program with string function) checks the entered number for 1) making sure each part is between 0 and 255 (if it's 256 or more, it's going to print a message saying one of the values...

  • Write a program that asks the user to enter a string and then asks the user...

    Write a program that asks the user to enter a string and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. python programming

  • Write a console-based program ( C # ) that asks a user to enter a number...

    Write a console-based program ( C # ) that asks a user to enter a number between 1 and 10. Check if the number is between the range and if not ask the user to enter again or quit. Store the values entered in an array. Write two methods. Method1 called displayByVal should have a parameter defined where you pass the value of an array element into the method and display it. Method2 called displayByRef should have a parameter defined...

  • Write a program that asks the user to enter a number ofseconds.• There are...

    Starting Out with C++ (9th Edition)  Chapter 4, Problem 7PCWrite a program that asks the user to enter a number of seconds.• There are 86400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86400, the program should display the number of days in that many seconds.• There are 3600 seconds in an hour. If the number of seconds entered by the user is less than 86400, but is greater...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT