[Solved] Printing a Decimal Number [closed]


Following is the program

    #include<stdio.h>
    main()
    {

      //float f = 233.1234;
      float f;
      float s;
      int x;
      int unit = 0;

      printf("Enter the decimal number \n");
      scanf("%f",&f);

      printf("Entered the decimal number =%f\n",f);

      s = f;

       while((int)s % 10) {
         s = s*10;
       }
       x = (int) s/10;

       printf("x=%d,s=%f \n",x,s);

       while(x % 10) {
         unit = unit + (x % 10);
         x = x / 10;
       }

       printf("Sum of the digit = %d \n",unit);


    }



// output in the terminal

Enter the decimal number 
233.1234
Entered the decimal number =233.123398
x=2331234,s=23312340.000000 
Sum of the digit = 18 

2

solved Printing a Decimal Number [closed]