Sayılarda Taban Çevirme


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int tabandan10a(int taban, int sayi);
void _10danTabana(int sayi, int taban);
int tabandanTabana(int tabandan, int sayidan, int tabana);
void basamak_yaz(int basamak);

int main()
{
printf(“Her hangi bir tabandan giris yapilirken en fazla 10 tabaninda sayi girilebilir.\n”
“Tabana ceviri yapilirkende en fazla 32 tabanina cevirili yapilabilir.\n………………..\n”);
int orjinal_taban, orjinal_sayi, cevrilecek_taban;
printf(“Orjinal tabanda ki sayi: “); scanf(“%d”, &orjinal_sayi);
printf(“Sayinin orjinal tabani: “); scanf(“%d”, &orjinal_taban);
printf(“Sayinin cevrilecegi taban: “); scanf(“%d”, &cevrilecek_taban);
printf(“%d tabaninda ki %d sayisinin %d tabaninda ki karsiligi: “, orjinal_taban, orjinal_sayi, cevrilecek_taban);
tabandanTabana(orjinal_taban, orjinal_sayi, cevrilecek_taban);

 printf(“\n”);
system(“PAUSE”);
return 0;
}

void _10danTabana(int sayi, int taban)
{
if(sayi/taban == 0)
{
basamak_yaz(sayi);
return;
}
else
{
_10danTabana(sayi/taban, taban);
basamak_yaz(sayi%taban);
}
}

int tabandan10a(int taban, int sayi)
{
int basamak_sayisi =0, cevrilmis_sayi=0, numara=sayi;
do{
basamak_sayisi++;
}while(numara/(int)pow(10, basamak_sayisi) != 0);
for(basamak_sayisi; basamak_sayisi>=0; basamak_sayisi–)
{
cevrilmis_sayi += (numara/(int)pow(10,basamak_sayisi))*(int)pow(taban, basamak_sayisi);
numara = numara%(int)pow(10, basamak_sayisi);
}
return cevrilmis_sayi;

}

int tabandanTabana(int tabandan, int sayidan, int tabana)
{
int ara10tabaninda;
ara10tabaninda = tabandan10a(tabandan, sayidan);
_10danTabana(ara10tabaninda, tabana);
}

void basamak_yaz(int basamak) 
{ 
 switch(basamak){ 
 case 0: 
 case 1: 
 case 2: 
 case 3: 
 case 4: 
 case 5: 
 case 6: 
 case 7: 
 case 8: 
 case 9: printf(“%d”, basamak); break; 
 case 10: printf(“A”); break; 
 case 11: printf(“B”); break; 
 case 12: printf(“C”); break; 
 case 13: printf(“D”); break; 
 case 14: printf(“E”); break; 
 case 15: printf(“F”); break; 
 case 16: printf(“G”); break; 
 case 17: printf(“H”); break; 
 case 18: printf(“I”); break; 
 case 19: printf(“J”); break; 
 case 20: printf(“K”); break; 
 case 21: printf(“L”); break; 
 case 22: printf(“M”); break; 
 case 23: printf(“N”); break; 
 case 24: printf(“O”); break; 
 case 25: printf(“P”); break; 
 case 26: printf(“Q”); break; 
 case 27: printf(“R”); break; 
 case 28: printf(“S”); break; 
 case 29: printf(“T”); break; 
 case 30: printf(“U”); break; 
 case 31: printf(“V”); break; 
 } 
}

Yorum Yapın

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑

%d blogcu bunu beğendi: