Azra
Bronze Üye
-
- Katılım
- 11 Mart 2014
-
- Mesajlar
- 3.834
-
- Tepkime puanı
- 13
-
- ForumSAL Yaşı:
- 12 yıl 7 ay
- Kıdem:
- Forumun Eskisi
-
- Yaş
- 35
Kod:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
char* binary(long int);
char* tersi(char*);
void main(void)
{
long int sayi = 0;
char *kod;
clrscr();
printf("\n Desimal-Binary donusturucu.");
printf("\n ===========================");
printf("\n\n Bir sayi giriniz: ");
scanf("%li",&sayi);
fflush(stdin);
kod = binary(sayi);
printf("\n Desimal : %li",sayi);
printf("\n Binary : %s ",kod);
getch();
}
char* binary(long int rakam)
{
long int temp = 0;
long int quot = 0;
int sayitut = 0;
int n = 0;
char sonuc[128]="";
char *ter;
temp = rakam;
while( temp > 1 )
{
sayitut = temp%2;
quot = temp/2;
temp = quot;
if( sayitut == 0 )
sonuc[n] = '0';
else
sonuc[n] = '1';
n++;
}
sonuc[n] = '1';
n++;
sonuc[n] = '\0';
ter = tersi(sonuc);
return ter;
}
char* tersi(char *kelime)
{
char terskelime[128] ="";
int uzunluk = 0;
int n = 0;
uzunluk = strlen(kelime);
for(n=0;n<uzunluk;n++)
{
terskelime[n] = kelime[uzunluk-n-1];
}
n++;
terskelime[n] = '\0';
return terskelime;
}