Skip to content

Instantly share code, notes, and snippets.

@pasali
Created January 8, 2012 23:12
Show Gist options
  • Save pasali/1580052 to your computer and use it in GitHub Desktop.
Save pasali/1580052 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
int yuvarla(float f , int sira)
{
int bi_onceki,secici;char a;
char d[100] ;
sprintf(d, "%f", f);// float'ı stringe çevirdik
int i= 0 ;
while( d[i] != '\0')
{
if (d[i] == '.')
{
secici = (d[i + sira]- 48);// karar basamaği
bi_onceki = (d[i + sira -1]- 48);
secici > 5 ? bi_onceki = bi_onceki + 1 : bi_onceki ;
a = bi_onceki + 48;// int 'i str yaptık
d[i + sira -1 ] = a;
d[i + sira ] ='\0';
}
i++;
}
puts(d);
}
int main()
{
yuvarla(1.2342, 3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment