Tuesday 20 August 2019

Add the integral and decimal part of a floating number without using . in scanf in C

#include<stdio.h>
int main()
{
    float x=12.25;
    int y=x,c=0;
    float d = x-y;
 
    for(; x !=((int)x);x = x*10)
    {
        c++;
    }
    while(c>0)
    {
        d=d*10;
        c--;
    }
    printf("%d",y+(int)d);

}

No comments:

Post a Comment