scan %f %lf\", &energy;, &power;); One last thing of When taking in character va
ID: 3789505 • Letter: S
Question
scan %f %lf", &energy;, &power;); One last thing of When taking in character variables (data type "char", with the conversion of specifier), note: and can interfere with the input a sometimes spaces and new line characters get always include correct chara when you read a character value, you should that reason, space before the conversion specifier. In other words, instead of this scanf("%c", &finitial;); ...you should type this: scan 96c", &finitial;); will Only do this with character variables. Also never put a space after the conversion specifier, as that prevent you from being able to end your scanf statement. With these things in mind, add the following input and output statements to Lab4.c: output Please input your first initial Input: finitial, character output: Please input your last initial: Input: Initial, character output: The initials you entered are finitial, character, linitial, character. (I recommend compiling and testing at this point to make sure your current statements work correctly!) Continue with the following statements: Output What is your age in years? Input years old, unsigned short integer Output So you are yearsold, unsigned short integer years old. Output: Please input the amount of energy used by the machineExplanation / Answer
// C code
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
char finitial, linitial;
printf("Please Input your first initial: ");
scanf(" %c",&finitial);
printf("Please Input your last initial: ");
scanf(" %c",&linitial);
printf("the initials you entered are %c and %c ",finitial,linitial);
unsigned short int age;
printf("What is your age in years: ");
scanf("%hu",&age);
printf("So you are %hu years old ", age);
double energy;
printf("Please input the amount of energy used by the machine: ");
scanf("%lf",&energy);
double work;
printf("Please input the amount of work done used by the machine: ");
scanf("%lf",&work);
double efficiency = work/energy*100;
printf("The efficiency of the machine is %5.1lf and it generated %6.2lf Joules of work ",efficiency,work);
double thetarad;
printf("Enter an angle in radians: ");
scanf("%lf",&thetarad);
printf("You input %lf. That is equal to %5.0lf degrees. ",thetarad,(thetarad*180/3.14));
printf("+---------------+--------------------+ ");
printf("Theta (radias) |%15f ",thetarad);
printf("sine (theta) |%15f ",sin(thetarad));
printf("cosine (theta) |%15f ",cos(thetarad));
printf("tangest (theta) |%15f ",tan(thetarad));
printf("+---------------+--------------------+ ");
return 0;
}
/*
output:
Please Input your first initial: a
Please Input your last initial: v
the initials you entered are a and v
What is your age in years: 24
So you are 24 years old
Please input the amount of energy used by the machine: 345
Please input the amount of work done used by the machine: 3444
The efficiency of the machine is 998.3 and it generated 3444.00 Joules of work
Enter an angle in radians: 1.05
You input 1.050000. That is equal to 60 degrees.
+---------------+--------------------+
Theta (radias) | 1.050000
sine (theta) | 0.867423
cosine (theta) | 0.497571
tangest (theta) | 1.743315
+---------------+--------------------+
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.