21) Find Minimum of Two Numbers
#include <iostream>
using namespace std;
int main() {
int a = 8, b = 3;
if(a < b)
cout << "Minimum = " << a;
else
cout << "Minimum = " << b;
return 0;
}
Output: Minimum = 3
22) Check Prime Number
#include <iostream>
using namespace std;
int main() {
int n = 7, flag = 1;
for(int i = 2; i <= n/2; i++) {
if(n % i == 0) {
flag = 0; break;
}
}
if(flag)
cout << "Prime";
else
cout << "Not Prime";
return 0;
}
Output: Prime
23) Sum of Digits
#include <iostream>
using namespace std;
int main() {
int n = 1234, sum = 0;
while(n != 0) {
sum += n % 10;
n /= 10;
}
cout << "Sum = " << sum;
return 0;
}
Output: Sum = 10
24) Greatest of Three Numbers
#include <iostream>
using namespace std;
int main() {
int a = 10, b = 20, c = 15;
if(a > b && a > c)
cout << "Greatest = " << a;
else if(b > c)
cout << "Greatest = " << b;
else
cout << "Greatest = " << c;
return 0;
}
Output: Greatest = 20
25) Check Alphabet or Not
#include <iostream>
using namespace std;
int main() {
char ch = 'A';
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
cout << "Alphabet";
else
cout << "Not Alphabet";
return 0;
}
Output: Alphabet
26) ASCII Value of Character
#include <iostream>
using namespace std;
int main() {
char ch = 'A';
cout << "ASCII = " << int(ch);
return 0;
}
Output: ASCII = 65
27) Vowel or Consonant
#include <iostream>
using namespace std;
int main() {
char ch = 'e';
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||
ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
cout << "Vowel";
else
cout << "Consonant";
return 0;
}
Output: Vowel
28) Check Positive Zero Negative
#include <iostream>
using namespace std;
int main() {
int n = 0;
if(n > 0)
cout << "Positive";
else if(n < 0)
cout << "Negative";
else
cout << "Zero";
return 0;
}
Output: Zero
29) Square of Number
#include <iostream>
using namespace std;
int main() {
int n = 9;
cout << "Square = " << n*n;
return 0;
}
Output: Square = 81
30) Cube of Number
#include <iostream>
using namespace std;
int main() {
int n = 3;
cout << "Cube = " << n*n*n;
return 0;
}
Output: Cube = 27