C Programming

C Programming-tutorials : part – 05

Written by Saiful Islam

Previous parts:

  1. Part 1
  2. Part 2
  3. Part 3
  4. Part 4

In my previous tutorial (part-4) we learned how to ask a user and get an integer number as input and how to show the result (the output).

Today I will show :

How to use float variables :

Actually there are very negligible different between using integer and float variables.

Let’s see those differences :

1. We have to use float instead of int.

2. We have used %f instead of %d.

[warning: Don’t copy paste the program (copy paste doesn’t work) just type the program on your compiler. ]

The output:

Now, if I enter 15 then the output becomes:

So, as we can see: the float variable, x has taken both of the integer number ( 15 ) and the rational number (0.36) as well.

If we use int and %d instead of float and %f than what will happen?

Answer:

79It’s a so easy to answer. Here, we will get only integer values whether the user gives a float value or not.

Stay collected with us.

🙂

About the author

Saiful Islam

4 Comments

Leave a Comment