Menu

(Solved) : Reads Two Real Numbers Keyboard Prints Productsample Program Include Int Main Int B Declar Q44086605 . . .

  1. Reads two real numbers from the keyboard andprints their product.Sample program:#include <stdio.h>int main(){int a, b; /* to declare that a and b are integer variables */printf(“Enter two integer numbers separated by space =”);scanf(“%d %d”, &a, &b); /* reads two integer numbers and assign them to a and b */printf(“The sum of the two numbers is %d.n”, a+b); /* %d is for integer format*/return 0;}
    • Use int for integers, floatfor floating (real) numbers.
    • To enter the value of a variable from the keyboard (standardinput), use scanf().
    • The scanf function reads input from thekeyboard in the format specified by (%d %d) and assigns each valueto the variable followed.
    • Use %d for integer and %f forfloat.
    • Add an ampersand (&) before each variable when using thescanf function for a reason too early todiscuss.
    • The printf function prints a string to thescreen (standard output). When it encounters a format (such as%d), it replaces that part by the variablefollowed.

  2. Reads a real number and outputs its inverse.If 0 is read, writes a warning message andquit.Sample program:#include <stdio.h>int main(){float a;printf(“Enter a number = “);scanf(“%f”, &a);if (a==0.0) printf(“You entered 0.n”); else printf(“You entered a number other than 0.n”);return 0;}
  3. Reads a real number, x, and outputsits sine, i.e. sin x. You need to use math.h andthe -lm compile option.Sampleprogram:#include <stdio.h>#include <math.h>int main(){float x;printf(“Enter a number =”); scanf(“%f”, &x);printf(“x= %f exp(x)=%fn”,x, exp(x));return 0;}Sample run (note the -lm option):$ gcc -lm myprogram.c$ a.out
  4. Write a program to solve the equation, a x +b = 0, for x. If a is 0, print a warningmessage and exit.Use the following as a template:#include <stdio.h>int main(){float a, b, x;printf(“Enter a and b separated by a comma=”); scanf(“%f, %f”, &a, &b);if (a==0) {…; return 0;}else x= ……;printf(……);return 0;}

Expert Answer


Answer to Reads two real numbers from the keyboard and prints their product.Sample program: #include int main() { int a, b; /* to…

OR