Question: Compose, execute and run the following programs and figure out what they do. Then, write C programs following the instructions. 1. Program that reads a

Compose, execute and run the following programs and figure out what they do. Then, write C programs following the instructions.

1. Program that reads a real number and outputs its inverse. If 0 is read, writes a warning message and quit.

Sample Program

#include  int main() { float a; printf("Enter a number = ");scanf("%f", &a); if (a==0.0) printf("You entered 0. "); else printf("You entered a number other than 0. "); return 0; } 

2. Reads a real number, x, and outputs its sine, i.e. sin x. You need to use math.h and the -lm compile option.

Sample Program

#include  #include  int main() { float x; printf("Enter a number ="); scanf("%f", &x); printf("x= %f exp(x)=%f ",x, exp(x)); return 0; } 

Sample Run

$ gcc -lm myprogram.c $ a.out 

3. Write a program to solve the equation, a x + b = 0, for x. If a is 0, print a warning message and exit.

Use the following as a template:

#include  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; } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!