C++ programında, bir koşula bağlı olarak farklı koşullar da kullanılabilir. Bu durumda If deyimi, iç içe (nested) yapıda kullanılabilir.
#include <iostream>
using namespace std;
int main() {
int num;
cout << "Bir tamsayı giriniz: ";
cin >> num;
// sayı 0 değilse çalış
if (num != 0) {
// sayının 2 ile bölümünden kalan 0 ise çifttir
if ((num % 2) == 0) {
cout << "Sayı çifttir." << endl;
}
// aksi durumda
else {
cout << "Sayı tektir." << endl;
}
}
// sayı 0 ise
else {
cout << "0 çift ya da tek sayı değildir." << endl;
cout << "Birler basamağında yer alirsa çift sayıyı oluşturur" << endl;
}
}#include <iostream>
using namespace std;
int main(){
int a;
cin >> a;
if (a <= 9) {
if (a==1) {
cout << "one";
}
else if (a==2) {
cout << "two";
}
else if (a==3) {
cout << "three";
}
else if (a==4) {
cout << "four";
}
else if (a==5) {
cout << "five";
}
else if (a==6) {
cout << "six";
}
else if (a==7) {
cout << "seven";
}
else if (a==8) {
cout << "eight";
}
else if (a==9) {
cout << "nine";
}
}
else{
cout << "Greater than 9";
}
return 0;
}