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 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.
PLEASE COMMENT YOUR CODE
Example input:
45
-3
13
Which should produce the following output:
142
-2
46
If you have any doubts, please give me comment...
#include<stdio.h>
int main(){
int x, result;
while(!feof(stdin)){
scanf("%d", &x);
result = 3*x+7;
printf("%d\n", result);
}
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.