In: Computer Science
Practice basic output formatting by reproducing the output below. All floating-point numbers should have 3 decimal places. Use these constants and values: NUM1= 10, NUM2= 1.49, and NUM3= 12.538767
Output:
NUM1 NUM2 NUM3
10 1.490 12.539
------------------------
123456789012345678901234 <-- DO NOT output this area. It is here to help you align things.
------------------------
Solve in C++.
#include<stdio.h>
#include<iostream>
using namespace std; \
int main()
{
float num1=10;
float num2=1.49;
float num3=12.538767;
//%-Xs : - sign puts the string to left side X denotes number of space occupy and s represents string
printf("%-10s%-10s%-10s\n","NUM 1","NUM 2","NUM 3");
// %-X.Yf : - sign puts number to left X denotes number of space occupied by whole number Y represent space occupied after decimal
printf("%-10.3f%-10.3f%-10.3f\n",num1,num2,num3);
return 0;
}
IF YOU HAVE ANY DOUBT THEN JUST LEAVE A COMMENT AND I WILL CLEAR YOUR DOUBT.