C++ Seçilen Harften Cümlede Kaç Tane Var?
Kullanıcının girdiği bir harf, yine kullanıcının girdiği bir cümlede kaç tane var?
ÇÖZÜM
#include <iostream>
#include <cstring>
using namespace std;
int main() {
string cumle;
char harf;
int toplam=0;
cout << "Bir Cumle Girin: ";
getline(cin, cumle);
cout << "Bir Harf Girin: ";
cin >> harf;
for(int i=0; i<cumle.length(); i++) {
char bul = cumle[i];
if(bul == harf) {
++toplam;
}
}
cout << "'" << cumle << "' cumlesinde " << toplam << " tane " << harf << " var.";
}
ÇIKTI