In: Computer Science
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)
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*/