Created
November 7, 2016 16:19
-
-
Save amanuel2/e8a9080ec92206c77d44886ba14abb29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| int powk(int x, unsigned int y) | |
| { | |
| if( y == 0) | |
| return 1; | |
| else if (y%2 == 0) | |
| return powk(x, y/2)*powk(x, y/2); | |
| else | |
| return x*powk(x, y/2)*powk(x, y/2); | |
| } | |
| void ftoa(float flt, int after_point) | |
| { | |
| int int_flt = (int) flt; | |
| printf("%d" , int_flt); | |
| printf("."); | |
| int mut_ab = powk(10,after_point); | |
| int after_point_flt = (int) (flt * mut_ab); //33314 | |
| int multiplier = powk(10,(after_point-1)); | |
| //printf("MULTIPLIER : %d\n" , multiplier); | |
| for(int xy=0; xy<after_point; xy++) | |
| { | |
| int muted = (after_point_flt/multiplier); | |
| //printf("%d\n",muted); | |
| muted = muted % 10; | |
| printf("%d", muted); | |
| multiplier/=10; | |
| } | |
| //printf("%d", after_point_flt); | |
| } | |
| int main(void) { | |
| float pi = 333.14434; | |
| ftoa(pi,5); | |
| printf("\n"); | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment