Professional Documents
Culture Documents
#include <iostream>
Int main() {
Return 0;
#include <iostream>
Int main() {
Int number;
Return 0;
#include <iostream>
Int main() {
// prints sum
Return 0;
#include <iostream>
Int main()
Return 0;
#include <iostream>
Int main()
Cout << “Size of char: “ << sizeof(char) << “ byte” << endl;
Cout << “Size of int: “ << sizeof(int) << “ bytes” << endl;
Cout << “Size of float: “ << sizeof(float) << “ bytes” << endl;
Cout << “Size of double: “ << sizeof(double) << “ bytes” << endl;
Return 0;
#include <iostream>
Int main()
A = b;
B = temp;
Return 0;
#include <iostream>
Int main() {
Int n;
Cin >> n;
If ( n % 2 == 0)
Else
Return 0;
#include <iostream>
Char c;
Cin >> c;
If (!isalpha©)
Else
Return 0;
#include <iostream>
Int main() {
Float n1, n2, n3;
Return 0;
#include <iostream>
#include <cmath>
Int main() {
Else if (discriminant == 0) {
X1 = -b/(2*a);
Else {
realPart = -b/(2*a);
imaginaryPart =sqrt(-discriminant)/(2*a);
cout << “x1 = “ << realPart << “+” << imaginaryPart << “I” << endl;
cout << “x2 = “ << realPart << “-“ << imaginaryPart << “I” << endl;
Return 0;
#include <iostream>
Int main() {
Int n, sum = 0;
Cout << “Enter a positive integer: “;
Cin >> n;
Sum += I;
Return 0;
#include <iostream>
Int main() {
Int year;
If (year % 400 == 0) {
// but divisible by 4
Else if (year % 4 == 0) {
Else {
Return 0;
#include <iostream>
Int main() {
Int n;
Cin >> n;
If (n < 0)
Else {
Factorial *= I;
}
Return 0;
#include <iostream>
Int main()
Int n;
Cin >> n;
Return 0;
#include <iostream>
Int main() {
Int n, t1 = 0, t2 = 1, nextTerm = 0;
Cout << “Enter the number of terms: “;
Cin >> n;
If(I == 1) {
Continue;
If(I == 2) {
Continue;
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
Return 0;
#include <iostream>
Int main() {
If ( n2 > n1) {
N2 = n1;
N1 = temp;
Hcf = I;
Return 0;
#include <iostream>
Int main()
Do
Break;
Else
++max;
} while (true);
Return 0;
#include <iostream>
Int main() {
Cin >> n;
While(n != 0) {
Remainder = n % 10;
N /= 10;
Return 0;
#include <iostream>
Int main()
Int exponent;
While (exponent != 0) {
Result *= base;
--exponent;
}
Cout << result;
Return 0;
#include <iostream>
Class Check
Private:
Int I;
Public:
Check(): i(0) { }
{ ++I; }
Void Display()
};
Int main()
Check obj;
Obj.Display();
++obj;
// Displays the value of data member I for object obj
Obj.Display();
Return 0;
#include <iostream>
Class Complex
Private:
Float real;
Float imag;
Public:
Void input()
// Operator overloading
Complex temp;
Return temp;
Void output()
If(imag < 0)
Cout << “Output Complex number: “<< real << imag << “I”;
Else
Cout << “Output Complex number: “ << real << “+” << imag << “I”;
};
Int main()
C1.input();
C2.input();
// the object on right hand side of operator is always assumed as argument by compiler.
Result = c1 – c2;
Result.output();
Return 0;
#include <iostream>
Int main() {
Char c;
Cin >> c;
Return 0;
#include <iostream>
Int main() {
#include <iostream>
Int main()
N = num;
Do
Cout << “ The reverse of the number is: “ << rev << endl;
If (n == rev)
Else
#include <iostream>
Int main() {
Int I, n;
Cin >> n;
If (n == 0 || n == 1) {
Is_prime = false;
If (n % I == 0) {
Is_prime = false;
Break;
If (is_prime)
Return 0;
#include <iostream>
Int main() {
Cout << “\nPrime numbers between “ << low << “ and “ << high << “ are: “ << endl;
Is_prime = true;
If (low == 0 || low == 1) {
Is_prime = false;
Is_prime = false;
Break;
If (is_prime)
++low;
Return 0;
#include <iostream>
Int main() {
originalNum = num;
while (originalNum != 0) {
originalNum /= 10;
If (result == num)
Else
Return 0;
#include <iostream>
#include <cmath>
Int main() {
Cout << “Armstrong numbers between “ << num1 << “ and “ << num2 << “ are: “ << endl;
Count = 0;
Num = I;
While(num > 0) {
++count;
Num /= 10;
// initialize sum to 0
Sum = 0;
Num = I;
// get sum of power of all digits of i
While(num > 0) {
Num /= 10;
If(sum == i) {
Return 0;
#include <iostream>
Int main() {
Int n, I;
Cin >> n;
If(n % I == 0)
Return 0;
#include <iostream>
Int main()
Int rows;
Cout << “* “;
Return 0;
# include <iostream>
Char op;
Switch(op) {
Case ‘+’:
Cout << num1 << “ + “ << num2 << “ = “ << num1 + num2;
Break;
Case ‘-‘:
Cout << num1 << “ – “ << num2 << “ = “ << num1 – num2;
Break;
Case ‘*’:
Cout << num1 << “ * “ << num2 << “ = “ << num1 * num2;
Break;
Case ‘/’:
Cout << num1 << “ / “ << num2 << “ = “ << num1 / num2;
Break;
Default:
Break;
Return 0;
#include <iostream>
Int check_prime(int);
Int main() {
Bool flag;
N2 = n1 + n2;
N1 = n2 – n1;
N2 = n2 – n1;
}
Cout << “Prime numbers between “ << n1 << “ and “ << n2 << “ are:\n”;
Flag = check_prime(i);
If(flag)
Return 0;
Int check_prime(int n) {
If (n == 0 || n == 1) {
Is_prime = false;
If (n%j == 0) {
Is_prime = false;
Break;
}
Return is_prime;
#include <iostream>
Bool check_prime(int);
Int main() {
Int n;
Cin >> n;
If (check_prime(n))
Else
Return 0;
Bool check_prime(int n) {
If (n == 0 || n == 1) {
Is_prime = false;
If (n % I == 0) {
Is_prime = false;
Break;
Return is_prime;
}…..
#include <iostream>
Int main() {
Int n, I;
Cin >> n;
If (check_prime(i)) {
If (check_prime(n – i)) {
Cout << n << “ = “ << I << “ + “ << n-I << endl;
Flag = true;
If (!flag)
Return 0;
Bool check_prime(int n) {
Int I;
If (n == 0 || n == 1) {
Is_prime = false;
If(n % I == 0) {
Is_prime = false;
Break;
}
Return is_prime;
#include<iostream>
Int main() {
Int n;
Cin >> n;
Return 0;
Int add(int n) {
If(n != 0)
Return 0;
#include<iostream>
Int main() {
Int n;
Cin >> n;
Return 0;
Int factorial(int n) {
If(n > 1)
Else
Return 1;
#include <iostream>
Int main()
{
Int n1, n2;
Cout << “H.C.F of “ << n1 << “ & “ << n2 << “ is: “ << hcf(n1, n2);
Return 0;
If (n2 != 0)
Else
Return n1;
#include <iostream>
#include <cmath>
// function prototype
Int main() {
Long long n;
Cin >> n;
Return 0;
// function definition
While (n!=0) {
Rem = n % 10;
N /= 10;
++I;
Return dec;
#include <iostream>
#include <cmath>
Int main()
{
Int octalNumber;
Return 0;
While (octalNumber != 0)
octalNumber /= 10;
++I;
Return decimalNumber;
#include <iostream>
// function prototype
Int main() {
String str;
Getline(cin, str);
// function call
Reverse(str);
Return 0;
// function definition
If(numOfChars == 1) {
Else {
// function recursion
#include <iostream>
Int main()
Cout << base << “^” << powerRaised << “ = “ << result;
Return 0;
If (powerRaised != 0)
Else
#include <iostream>
Int n, I;
Cin >> n;
Cin >> n;
Sum += num[i];
Average = sum / n;
Return 0;
#include <iostream>
Using namespace std;
Int main() {
Int I, n;
Float arr[100];
Cin >> n;
Arr[0] = arr[i];
Return 0;
}
#include <iostream>
#include <cmath>
Int main() {
Int I;
Float data[10];
Return 0;
Int I;
Sum += data[i];
}
Mean = sum / 10;
#include <iostream>
Int main()
Cin >> r;
Cin >> c;
Cout << endl << “Enter elements of 1st matrix: “ << endl;
Cout << endl << “Enter elements of 2nd matrix: “ << endl;
Cout << endl << “Sum of two matrix is: “ << endl;
If(j == c – 1)
}
Return 0;
#include <iostream>
Int main()
While (c1!=r2)
Cout << “Error! Column of first matrix not equal to row of second.”;
#include <iostream>
Using namespace std;
Int main()
While (c1!=r2)
Cout << “Error! Column of first matrix not equal to row of second.”;
Cout << endl << “Enter elements of matrix 1:” << endl;
{
Cout << “Enter element a” << I + 1 << j + 1 << “ : “;
Cout << endl << “Enter elements of matrix 2:” << endl;
Mult[i][j]=0;
If(j == c2-1)
Return 0;
#include <iostream>
Int main() {
}
}
If (j == column – 1)
Transpose[j][i] = a[i][j];
If (j == row – 1)
Return 0;
}
#include <iostream>
Void enterData(int firstMatrix[][10], int secondMatrix[][10], int rowFirst, int columnFirst, int rowSecond,
int columnSecond);
Void multiplyMatrices(int firstMatrix[][10], int secondMatrix[][10], int multResult[][10], int rowFirst, int
columnFirst, int rowSecond, int columnSecond);
Int main()
// If colum of first matrix in not equal to row of second matrix, asking user to enter the size of
matrix again.
Cout << “Error! Column of first matrix not equal to row of second.” << endl;
}
// Function to take matrices data
Return 0;
Void enterData(int firstMatrix[][10], int secondMatrix[][10], int rowFirst, int columnFirst, int rowSecond,
int columnSecond)
Int I, j;
Cout << endl << “Enter elements of matrix 1:” << endl;
Cout << endl << “Enter elements of matrix 2:” << endl;
For(I = 0; I < rowSecond; ++i)
Void multiplyMatrices(int firstMatrix[][10], int secondMatrix[][10], int mult[][10], int rowFirst, int
columnFirst, int rowSecond, int columnSecond)
Int I, j, k;
Mult[i][j] = 0;
{
For(k=0; k<columnFirst; ++k)
Int I, j;
If(j == columnSecond – 1)
#include <iostream>
Int main()
{
Int data[5];
Return 0;
#include<iostream>
Int main()
Int a, b, c;
Cout << “a, b and c respectively are: “ << a << “, “ << b << “, “ << c << endl;
cyclicSwap(&a, &b, &c);
cout << “a, b and c respectively are: “ << a << “, “ << b << “, “ << c << endl;
return 0;
Int temp;
Temp = *b;
*b = *a;
*a = *c;
*c = temp;
#include <iostream>
Int main()
Int count = 0;
{
If (str[i] == checkCharacter)
++ count;
Return 0;
#include <iostream>
Int main()
Char line[150];
Cin.getline(line, 150);
Line[i]==’U’)
{
++vowels;
++consonants;
++digits;
Else if (line[i]==’ ‘)
++spaces;
Return 0;
#include <iostream>
Int main() {
String line;
Getline(cin, line);
If ((line[i] >= ‘a’ && line[i] <= ‘z’) || (line[i] >= ‘A’ && line[i] <= ‘Z’)) {
Line = temp;
Return 0;
#include <iostream>
Int main() {
Return 0;
#include <iostream>
Using namespace std;
Int main()
Result = s1 + s2;
Return 0;
#include <iostream>
Int main()
Return 0;
#include <iostream>
Int main()
Getline(cin, str[i]);
Temp = str[j];
Str[j + 1] = temp;
}
}
Return 0;
#include <iostream>
Struct student
Char name[50];
Int roll;
Float marks;
};
Int main()
Student s;
Return 0;
#include <iostream>
Struct Distance {
Int feet;
Float inch;
Int main() {
Sum.feet = d1.feet+d2.feet;
Sum.inch = d1.inch+d2.inch;
// extra feet
Sum.feet += extra;
Cout << endl << “Sum of distances = “ << sum.feet << “ feet “ << sum.inch << “ inches”;
Return 0;
#include <iostream>
Float real;
Float imag;
} complexNumber;
int main() {
char signOfImag;
cout << “Enter real and imaginary parts respectively:” << endl;
Cout << “Enter real and imaginary parts respectively:” << endl;
cout << “Sum = “ << complexSum.real << signOfImag << complexSum.imag << “I”;
return 0;
}
complex temp;
return (temp);
#include <iostream>
Struct TIME
Int seconds;
Int minutes;
Int hours;
};
Int main()
cout << endl << “TIME DIFFERENCE: “ << t1.hours << “:” << t1.minutes << “:” << t1.seconds;
cout << “ – “ << t2.hours << “:” << t2.minutes << “:” << t2.seconds;
cout << “ = “ << difference.hours << “:” << difference.minutes << “:” << difference.seconds;
return 0;
Void computeTimeDifference(struct TIME t1, struct TIME t2, struct TIME *difference){
--t1.minutes;
T1.seconds += 60;
--t1.hours;
T1.minutes += 60;
}
Difference->minutes = t1.minutes-t2.minutes;
Difference->hours = t1.hours-t2.hours;
#include <iostream>
Struct student
Char name[50];
Int roll;
Float marks;
} s[10];
Int main()
// storing information
S[i].roll = i+1;
Cout << “For roll number” << s[i].roll << “,” << endl;
// Displaying information
Return 0;