C++ Example
C++ Example
#include <iostream>
using namespace std;
int main()
{
int n, i;
bool isPrime = true;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
char c;
int isLowercaseVowel, isUppercaseVowel;
return 0;
}
int main()
{
int n, num, digit, rev = 0;
n = num;
do
{
digit = num % 10;
rev = (rev * 10) + digit;
num = num / 10;
} while (num != 0);
cout << " The reverse of the number is: " << rev << endl;
if (n == rev)
cout << " The number is a palindrome";
else
cout << " The number is not a palindrome";
return 0;
}
Roots of a Quadratic Equation
#include <iostream>
#include <cmath>
using namespace std;
int main() {
else if (discriminant == 0) {
cout << "Roots are real and same." << endl;
x1 = (-b + sqrt(discriminant)) / (2*a);
cout << "x1 = x2 =" << x1 << endl;
}
else {
realPart = -b/(2*a);
imaginaryPart =sqrt(-discriminant)/(2*a);
cout << "Roots are complex and different." << endl;
cout << "x1 = " << realPart << "+" << imaginaryPart << "i" << endl;
cout << "x2 = " << realPart << "-" << imaginaryPart << "i" << endl;
}
return 0;
}
#include <iostream>
using namespace std;
struct student
{
char name[50];
int roll;
float marks;
};
Store and Display Information Using Structure
int main()
{
student s;
cout << "Enter information," << endl;
cout << "Enter name: ";
cin >> s.name;
cout << "Enter roll number: ";
cin >> s.roll;
cout << "Enter marks: ";
cin >> s.marks;
#include <iostream>
using namespace std;
int main()
{
float n1, n2, n3;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
float n1, n2, n3;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int i, n;
float arr[100];
return 0;
}
#include <iostream>
using namespace std;
Finding GCD Program
int main()
{
int n1, n2;
while(n1 != n2)
{
if(n1 > n2)
n1 -= n2;
else
n2 -= n1;
}
#include <iostream>
using namespace std;
Factorial Example
int main()
{
int i, n, factorial = 1;
int main()
{
int n;
cout << "Enter a positive integer: ";
cin >> n;
return 0;
}
int main()
{
int n, i;
float num[100], sum=0.0, average;
average = sum / n;
cout << "Average = " << average;
return 0;
}
Simple Calcualator
# include <iostream>
using namespace std;
int main()
{
char op;
float num1, num2;
switch(op)
{
case '+':
cout << num1+num2;
break;
case '-':
cout << num1-num2;
break;
case '*':
cout << num1*num2;
break;
case '/':
cout << num1/num2;
break;
default:
// If the operator is other than +, -, * or /, error message is shown
cout << "Error! operator is not correct";
break;
}
return 0;
}
https://www.programiz.com/cpp-programming/examples/standard-deviation
https://tekhnologic.wordpress.com/2017/06/24/10-more-powerpoint-games/#theballoongame