Computer Programming Learning Part-04||Week-04||C++ program to divide two numbers using floating number.
Steemian Friends,
Today, I will write Computer Programming Learning Part-04. I will show floating-number programming in a C++ program. In the previous parts, I have shown programming with integer numbers. Hopefully, I can learn C++ programs with floating numbers from today's learning part. Today, I will show a C++ program to divide two floating numbers.
Design By Canva
Floating number:
We do addition, subtraction, and multiplication with Integer numbers. But decimal numbers are called floating to program in C++. There are two types of floating numbers: single floating and double floating. Single floating is 32 bits, and double floating is 64 bits. Today, I will show a C++ program with Single Floating as an example. So, let's begin.
I first open the Block Codes software. Then I go to File and click on New. Then, I click on the Empty File option and turn on the program writing page. I have shown it as a red block in the picture below.
Then, I will declare the Header file and Main function. Every C++ program has to write these two parts at the beginning. I have written it below.
#include<stdio.h>
int main ()
{}
Then, I declared a floating variable, which is written with a and b. It is written below.
float a;
float b;
Then, I declared two floating numbers, which will sit as the values of a and b. Two floating numbers are a=9.5 and b=7.3. Below is the program written.
a= 9.5;
b=7.3;
Then, I will divide the above two floating numbers. I have written the following C++ program to divide the floating number and see the result.
Printf (" result : %f\n",a/b);
return 0 ;
Completed the program with
Then I read the entire program once. Then, I clicked on the Run program option. Then, I looked at the bottom of the program; there was no error. If there had been a mistake, it would show the error in red letters at the bottom. There are no errors in writing my program.
Then I see the program's output. It shows the result of dividing two floating numbers. The result shows six digits after the decimal point. Two or three numbers can be shown after the decimal if desired.
Then, I have written below the work to be done to display three digits after the decimal of the result.
Printf("result : % 0.3 f\n",a/b);
Link to my previous post:
Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
please click it!
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)
The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.
This is my Twitter share link :
https://twitter.com/mahadih83660186/status/1793570123569311768?t=Tjz5DyVNiKo-7X8qKQELrg&s=19
We support quality posts and good comments posted anywhere and with any tag.
Curated by : @𝗁𝖾𝗋𝗂𝖺𝖽𝗂
Thank You Dear Sir....