C++ Metot Kullanarak Tek Çift Sayı Kontrolü

S

Spectrum Artz

Web | Graphics
Ultra Member
Joined
Jul 31, 2019
Messages
525
Reaction score
111
C++:
bool ciftMi(int sayi){
    if(sayi%2==0){
        return true;
    }
    else{
        return false;
    }
    
}

Daha sonra ana programımızda For Döngüsü yardımıyla kullanıcının sayı girişi yapmasını sağlayacağız. Girilen sayıları fonksiyona göndererek kontrolünü sağlayacağız ve gerekli işlemleri yapacağız.


C++:
int main()
{
    setlocale(LC_ALL,"Turkish"); //Türkçe karakter
    int sayi;
    int tekAdet=0,ciftAdet=0;
    for(int i=1;i<=10;i++)
    {
        cout<<i<<". Sayı : ";
        cin>>sayi;
        
        if(ciftMi(sayi))
        {
            ciftAdet++;
        }
        else
        {
            tekAdet++;
        }
        
    }
    cout<<"---------- www.yazilimkodlama.com ----------"<<endl;
    cout<<"Girilen Tek Sayıların Adeti : "<<tekAdet<<endl;
    cout<<"Girilen Çift Sayıların Adeti : "<<ciftAdet<<endl;
}
 
SPAM IS FORBIDDEN!
  • SPAMMERS ARE BANNED FROM THE FORUM AND CANNOT USE ANY OF THE CHEATS
  • For example: thanks, thx, very good, asdqwe, working, ty and so on!
  • For example: Writing the same message over and over. thanks, thx and so on!
  • Copying and copying someone else's message is prohibited.
  • It is forbidden to send messages to increase the number of comments on threads that you have no knowledge of.
  • Write your own opinion when commenting!
  • If you see spam message, please let us know with the REPORT button!

Tema düzenleyici

Top Bottom