Thursday, September 13, 2018

DT-10: FLOAT TO INTEGER


  • Problem Description

    Write a C program to convert Float to Integer number

    If the value exceed 0.5 then add one to the integer component
  • CODING ARENA
  • #include <stdio.h>
    int main()
    {
      float a,b;
      int x,y;
      scanf("%f%f",&a,&b);
      x=(int)(a+0.5);
      y=(int)(b+0.5);
      printf("Value is:%d",x);
      printf("\nValue is:%d",y);
        

    return 0;
    }
  • Test Case 1

    Input (stdin)
    4.6
    
    5.8
    
    
    Expected Output
    Value is:5
    
    Value is:6
  • Test Case 2

    Input (stdin)
    9.4
    
    9.5
    
    
    Expected Output
    Value is:9
    
    Value is:10

No comments:

Post a Comment