Şimdi Ara

Sizin için pek zor olmasa gerek ödev için acil bir yardım lazım dı

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
2 Misafir - 2 Masaüstü
5 sn
4
Cevap
0
Favori
535
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
Öne Çıkar
0 oy
Sayfa: 1
Giriş
Mesaj
  • WATCOM DA

    #include<stdio.h>
    #include<conio.h>

    void main()
    {
    int a,b,count,apowb;
    char reply;
    count = 0;
    apowb = 1;
    do
    {
    printf("Enter a number:");
    scanf("%d",&a);
    printf("Which power of %d you want to get:",a);
    scanf("%d",&b);
    if(b==0)
    {
    printf("Result is equal to 1");
    }
    else
    {
    while (count < b)
    {
    apowb = apowb * a ;
    count = count + 1;
    }
    printf("Result is equal to %d\n:",apowb);
    }
    printf("Repeat operation? Y/N\n");
    reply=getch();
    }
    while(reply=="y" || reply=="Y");
    }


    BUNLARI YAZDIM FAKAT 2 ADET PROBLEMIM VAR B=0 IKEN PROGRAM 1 YAZMIYOR VE KAPANIRKEN 1 I GOSTERIYOR , AYRICA PROGRAMIN KENDINI TEKRAR ETMESINI YAPAMADIM "Y" TUSUNA BASILDIGINDA KENDINI TEKRARLAMAISNI ISTIYORUM FAKAT HALA SONUCA ULASAMADIM.BIRDE ACABA A BUYUKTUR 0 VE B BUYUK ESITTIR 0 DEMEM LAZIM ONU NEREYE NASIL YERLESTIREBILIRIM , YARDIMCI OLURSANIZ COK SEVINIRIM , TESEKKURLER..



    _____________________________




  • quote:

    Orijinalden alıntı: shopar39

    WATCOM DA

    #include<stdio.h>
    #include<conio.h>

    void main()
    {
    int a,b,count,apowb;
    char reply;
    count = 0;
    apowb = 1;
    do
    {
    printf("Enter a number:");
    scanf("%d",&a);
    printf("Which power of %d you want to get:",a);
    scanf("%d",&b);
    if(b==0)
    {
    printf("Result is equal to 1");
    }
    else
    {
    while (count < b)
    {
    apowb = apowb * a ;
    count = count + 1;
    }
    printf("Result is equal to %d\n:",apowb);
    }
    printf("Repeat operation? Y/N\n");
    reply=getch();
    }
    while(reply=="y" || reply=="Y");
    }


    BUNLARI YAZDIM FAKAT 2 ADET PROBLEMIM VAR B=0 IKEN PROGRAM 1 YAZMIYOR VE KAPANIRKEN 1 I GOSTERIYOR , AYRICA PROGRAMIN KENDINI TEKRAR ETMESINI YAPAMADIM "Y" TUSUNA BASILDIGINDA KENDINI TEKRARLAMAISNI ISTIYORUM FAKAT HALA SONUCA ULASAMADIM.BIRDE ACABA A BUYUKTUR 0 VE B BUYUK ESITTIR 0 DEMEM LAZIM ONU NEREYE NASIL YERLESTIREBILIRIM , YARDIMCI OLURSANIZ COK SEVINIRIM , TESEKKURLER..

    o reply'in olduğu while yanlış kurulmuş gibi geldi sanki
    ilk önce reply'a 'Y' veya 'y' diyerek açılır program while kurulur içine yukarıdaki kodlar yazılır, daha sonra en son kod yine char alma(getc()) olur reply yine y ise devam eder,

    NOT Test ettim çalışıyor. Do while yapmadım normal while yaptım. Hatan muhtemelen yanlış yere \n koymakla ilgiliydi, bir de char'a değer atamada galiba.
    #include<stdio.h> 
    #include<conio.h>

    void main()
    {
    char reply = 'Y';

    while(reply=='y' || reply=='Y')
    {
    int a,b,count,apowb;
    count = 0;
    apowb = 1;

    printf("Enter a number:");
    scanf("%d",&a);
    printf("Which power of %d you want to get:",a);
    scanf("%d",&b);
    if(b==0)
    {
    printf("Result is equal to 1\n");
    }
    else
    {
    while (count < b)
    {
    apowb = apowb * a ;
    count = count + 1;
    }
    printf("Result is equal to %d:\n",apowb);
    }
    printf("Repeat operation? Y/N\n\n");
    reply=getch();
    }
    }
    _____________________________




  • a veya b 0 dan küçükse çalışmıyor elbette aslında bu ihtimaller denk geldiğinde program sonlandırılmalı ama bunun yerine ben do while içine aldım onları, uygun sayı girilene kadar soruyor
    a=0 ve b=0 ise sonuç 1, a=0 b=x için sonuç 0
    Ayrıca en önemli hata count ve apowb değişkenlerini do-while içinde tekrar ilk değerlerine döndürmemen. Bu yüzden program sadece ilk çalıştığında doğru sonuç veriyor diğerlerinde yanlış sonuç veriyordu.
    Biraz kafama göre makyaj yaptım kusura bakma

     

    #include<stdio.h>
    #include<conio.h>

    int main() //main in return turu int olmali
    {
    int a, b;
    unsigned long long apowb; //daha buyuk sayilarda dogru sonuc vermesi icin
    char reply;

    do
    {
    do
    {
    printf("Enter a number: ");
    scanf("%d", &a);
    if (a < 0)
    printf("Error: Negative number.\n\n");
    }
    while (a < 0);

    do
    {
    printf("Which power of %d you want to get: ", a);
    scanf("%d", &b);
    if (b < 0)
    printf("Error: Negative number.\n\n");
    }
    while (b < 0);


    if(b == 0)
    printf("\n%d^%d = 1\n\n", a, b);

    else if (a == 0)
    printf("\n%d^%d = 0\n\n", a, b);

    else
    {
    apowb = 1; //her do-while dongusunde apowb ve count ilk degerlerine getirilmeli
    for (int count = 0; count < b; ++count) //count = count + 1
    apowb *= a; // apowb = apowb * a;

    printf("\n%d^%d = %llu\n\n", a, b, apowb); //%llu unsigned long long icin
    }
    printf("Repeat operation? Y/N\n\n");
    reply = getch();
    }
    // y ve Y string degil karakter bu yuzden tek tirnak icine alinmali
    while(reply == 'y' || reply == 'Y');

    return 0;
    }




    < Bu mesaj bu kişi tarafından değiştirildi crshr -- 20 Ocak 2012; 23:29:04 >




  • çok çok teşekkürler yardımlarnız için :)
    _____________________________
  • Yapay Zeka’dan İlgili Konular
    Daha Fazla Göster
    
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.