Create a C program that evaluates the function 3x + 7.
Your input will consist of a number of lines, each containing a single integer number. For each number x that is provided in the input, you should output 3x + 7 as a single integer number. Each number your program prints has to occupy a separate line. No other character should be sent to the output other than the digits of the number (and possible sign) and the newline character. As such, the number of lines that your program prints should equal the number of input lines.
Your C program should be able to parse input provided in the standard input. Unless redirected, the standard input will be the keyboard. You can assume that the input has no errors.
Example input:
45
-3
13
Which should produce the following output:
142
-2
46
#include <stdio.h> int main() { int x; // declare variable x while (scanf("%d", &x) == 1) { // read numbers from user. // we are checking if return type of scanf to be 1 because if user enter an integer then scanf returns 1, else it returns -1 // if scanf("%d", &x) == 1, then an integer was read from user into x // if scanf("%d", &x) not equal 1, then an integer was not read from user into x. so, we need to exit the loop. printf("%d\n", 3*x + 7); // display 3x+7 } return 0; }
Get Answers For Free
Most questions answered within 1 hours.