Question

In: Computer Science

In coding language C, Write a program in which will use floating point variable (input=232.346) and...

In coding language C, Write a program in which will use floating point variable (input=232.346) and print out: 1. scientific notation form of input. 2. floating point form of input with total width 12 (default right aligned). 3. floating point form of input with total width 12 (default right aligned) and add 0s for unused space. 4. floating point form of input with total width 12 (left aligned). 5. floating point form of input with total width 12 (default right aligned) and limit number of digits after decimal point to 2 i.e. (precision of 2 digits)

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

#include<stdio.h>

int main(){

                //declaring a floating point number

                float input=232.346;

                //Scientific notation:

                printf("%e\n",input);

                //Floating point form with width 12, default right aligned

                printf("%12f\n",input);

                //Floating point form with width 12 with 0 padding:

                printf("%012f\n",input);

                //Floating point form with width 12 left aligned

                printf("%-12f\n",input);

                //Floating point form with width 12, default right aligned, with 2 digits

                //after decimal point

                printf("%12.2f\n",input);

                return 0;

}

/*OUTPUT*/


Related Solutions

Use C language Write a program that reads in a series of lines of input character...
Use C language Write a program that reads in a series of lines of input character by character (using getchar()). The first line of the input contains an integer which specifies the number of remaining lines of input, each of which contains a floating point number. The integer value on the first line can be read with scanf(), but all of the following lines can only be read with getchar(). Each line after the first contains a single floating point...
Write a program that asks the user to input a set of floating-point values. When the...
Write a program that asks the user to input a set of floating-point values. When the user enters a value that is not a number, give the user a second chance to enter the value. After two chances, quit reading input. Add all correctly specified values and print the sum when the user is done entering data. Use exception handling to detect improper inputs.5 pts Your code with comments A screenshot of the execution Test Case:       Enter float: 1.0...
Use C++ language Create a program which will ask the user to input three songs for...
Use C++ language Create a program which will ask the user to input three songs for a playlist (you may use TV shows or movies, if you prefer). Declare three strings to store each of the songs. Use getline to receive the input. Display output which lists each of the songs (or movies or tv shows), on separate lines, with a title on the first line: My Playlist. Insert three lines of comments at the beginning of the program for...
[C++ Coding question] write a program which inputs data to a two-dimensional array: - Input number...
[C++ Coding question] write a program which inputs data to a two-dimensional array: - Input number of rows r aand number of columns c - Create a two-dimensional array of integers int numbers[r][c] -input data for each element of numbers Your program must compute and display the largest number is each row and column of the number array
Write a program to create a tree randomly. You can use C++ programming language. The input...
Write a program to create a tree randomly. You can use C++ programming language. The input is the number of vertices in the tree, and the output is an adjacent list of the tree. (Managed to complete this assignment with a binary tree. But, was told I needed a general tree instead)
Write a program that calculates the compound interest for an investment. (C++ coding language) If you...
Write a program that calculates the compound interest for an investment. (C++ coding language) If you deposit an amount of money P , the principal, at an interest rate r then the interest will compound over time. This means that the interest earned each period becomes part of the principal and the next time you get interest you earn interest on the interest. This is known as compounding. The equation for compound interest is ( r)n·t Pn=P0 1+n where P0...
Create program which verifies if input string is a valid variable declaration or not. Use C...
Create program which verifies if input string is a valid variable declaration or not. Use C programming language. - This program can only use the following variable types: char, float, and int - Remove any newline \n from input string - The input prompt should say ">>> " - If input declaration is valid, it should print "Valid dec\n" - If input declaration is invalid, it should print "Invalid dec\n" - Make sure the identifier entered matches the rules of...
Using double precision floating point arithmetic, write a( MIPS )program that will convert input temperatures in...
Using double precision floating point arithmetic, write a( MIPS )program that will convert input temperatures in Fahrenheit to Celsius. The program should prompt the user for a temperature in Fahrenheit and then print the corresponding temperature in Celsius. The formula for the conversion is: C = 5/9 * (F – 32)
JAVA Write a program that translates a user-input floating-point number between 0 and 4 into the...
JAVA Write a program that translates a user-input floating-point number between 0 and 4 into the closest letter grade. For example, the number 2.8 (which might have been the average of several grades) would be converted to B–. Break ties in favor of the better grade; for example 2.85 should be a B. NOTE: Your implementation must include the definition/implementation and use/calling of the method numberGradeToLetterGrade that is passed a double numeric grade to its parameter variable, and returns the...
Language: C++ In your main(), use printf() to print out the floating point values for some...
Language: C++ In your main(), use printf() to print out the floating point values for some hex data. a. To print 1.0, do printf("One: %f\n",0x3FF0000000000000); The compiler will give you a warning about the argument being a different type than the format, but that is ok. b. To print 2.0, do printf("Two: %f\n",0x4000000000000000); Remember, to multiply by two, you just add one to the exponent. c. Print 4.0, 8.0, and 16.0 (with nice labels, of course). d. We can also...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT