C++ Fonksiyon Kullanarak Tek / Çift Sayı Kontrolü

S

Spectrum Artz

Web | Graphics
Ultra Member
Joined
Jul 31, 2019
Messages
525
Reaction score
111
Örneğimizde “ciftMi” adında geriye true yada false değeri döndüren bool türünde bir fonksiyon oluşturacağız.

Kodlarımızın tamamı ve ekran çıktısı aşağıdaki gibi olacaktır.




C++:
#include <iostream>
#include<stdlib.h>
using namespace std;
 
bool ciftMi(int sayi){
    if(sayi%2==0){
        return true;
    }
    else{
        return false;
    }
    
}
 
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;
}
cpp-fonksiyon-tek-cift.jpg
 
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