Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to read and display real numbers in C?

+12 votes
asked Sep 17, 2017 by Admin (5,100 points)
I want to read and numbers like 2.52. How can I do that in C program?

4 Answers

0 votes
answered Sep 17, 2017 by Admin (5,100 points)

You can use '%f' format specifier to read/write real numbers. Here is an example.

0 votes
answered Oct 4, 2017 by anonymous
use float varibale

%f specifier
0 votes
answered Sep 22 by Mohammed Raiyan (230 points)
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter a floating-point number: ");
        if (scanner.hasNextFloat()) {
            float number = scanner.nextFloat();
            System.out.printf("You entered: %.2f%n", number);
        } else {
            System.out.println("Invalid input. Please enter a valid floating-point number.");

0 votes
answered Sep 27 by hari shankar (140 points)
answer in c programme;

void main()
  float n;
  printf ("enter the value you want:\n");
  scanf ("%f", &n);
  printf ("the number is: %0.2f",n);
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.