This Program prints the ASCII value of given variable
#include <iostream.h>
int main()
{
char one_char;
cout << "\nEnter a character: ";
cin >> one_char;
cout << "The character you entered was " << one_char << '\n';
cout << "Its ASCII value is " << (int) one_char << '\n';
return 0;
}
This Program demonstrates the getch() function
#include <iostream.h>
#include <conio.h>
int main()
{
int one_char;
cout << "\nEnter a character: ";
one_char = getch();
cout << "\nThe character you entered was "<< (char) one_char << '\n';
cout << " Its ASCII value is "<< (int) one_char << '\n';
return 0;
}
This Program demonstrate relational operators
#include <iostream.h>
int main()
{
int first, second;
cout << "\nInput two numbers ";
cin >> first >> second;
cout << "First > second has the value "<< (first > second) << '\n';
cout << "first < second has the value " << (first < second) << '\n';
cout << "first == second has the value "<< (first == second) << '\n';
return 0;
}
This Program demonstrate the TAB(‘\t’) key inside the C++ program
#include <iostream.h>
int main()
{
int i = 101, j = 59, k = 0;
int m = 70, n = 85, p = 5;
int q = 39, r = 110, s = 11;
cout << '\t' << "Won" << '\t' << "Lost" << '\t' << "Tied\n\n";
cout << "Eagles" << '\t' << i << '\t' << j << '\t' << k << '\n';
cout << "Lions" << '\t' <<m << '\t' << n << '\t' << p << '\n';
cout << "Wombats" << '\t' << q << '\t' << r << '\t' << s << '\n';
return 0;
}
This Program demonstrates different mathematical operations
#include <iostream.h>
int main()
{
float result;
result = 1.0 + 2.0 * 3.0 / 4.0;
cout << '\n' << result;
result = 1.0 / 2.0 + 3.0;
cout << '\n' << result;
result = (1.0 + 2.0) / 3.0;
cout << '\n' << result;
result = (1.0 + 2.0 / 3.0) + 4.0;
cout << '\n' << result;
return 0;
}
This Program demonstrates the IF conditional statement to check the condition
#include <iostream.h>
int main()
{
int your_number;
cout << "Enter a whole number: ";
cin >> your_number;
if (your_number % 2 == 0)
cout << "\nYour number is even\n";
if (your_number % 2 != 0)
{
cout << "Your number is odd.\n";
}
cout << "That's all!\n";
return 0;
}
This Program demonstrates IF….ELSE conditional statement
#include <iostream.h>
int main()
{
int your_number;
cout << "Enter a whole number: ";
cin >> your_number;
if (your_number % 2 == 0)
cout << "Your number is even\n";
else
{
cout << "Your number is odd.\n";
}
cout << "That's all!\n";
return 0;
}
This Program demonstrates the IF….ELSEIF nested conditional statements
#include <conio.h>
#include <iostream.h>
#include <ctype.h>
int main()
{
char cmd;
cout << "Chart desired: Pie Bar Scatter Line Three-D";
cout << "\n Press first letter of the chart you want: ";
cmd = toupper(getch());
cout << '\n';
if (cmd == 'P')
cout << "Doing pie chart\n";
else if (cmd == 'B')
cout << "Doing bar chart\n";
else if (cmd == 'S')
cout << "Doing scatter chart\n";
else if (cmd == 'L')
cout << "Doing line chart\n";
else if (cmd == 'T')
cout << "Doing 3-D chart\n";
else cout << "Invalid choice.\n";
return 0;
}
#include <iostream.h>
int main()
{
char one_char;
cout << "\nEnter a character: ";
cin >> one_char;
cout << "The character you entered was " << one_char << '\n';
cout << "Its ASCII value is " << (int) one_char << '\n';
return 0;
}
This Program demonstrates the getch() function
#include <iostream.h>
#include <conio.h>
int main()
{
int one_char;
cout << "\nEnter a character: ";
one_char = getch();
cout << "\nThe character you entered was "<< (char) one_char << '\n';
cout << " Its ASCII value is "<< (int) one_char << '\n';
return 0;
}
This Program demonstrate relational operators
#include <iostream.h>
int main()
{
int first, second;
cout << "\nInput two numbers ";
cin >> first >> second;
cout << "First > second has the value "<< (first > second) << '\n';
cout << "first < second has the value " << (first < second) << '\n';
cout << "first == second has the value "<< (first == second) << '\n';
return 0;
}
This Program demonstrate the TAB(‘\t’) key inside the C++ program
#include <iostream.h>
int main()
{
int i = 101, j = 59, k = 0;
int m = 70, n = 85, p = 5;
int q = 39, r = 110, s = 11;
cout << '\t' << "Won" << '\t' << "Lost" << '\t' << "Tied\n\n";
cout << "Eagles" << '\t' << i << '\t' << j << '\t' << k << '\n';
cout << "Lions" << '\t' <<m << '\t' << n << '\t' << p << '\n';
cout << "Wombats" << '\t' << q << '\t' << r << '\t' << s << '\n';
return 0;
}
This Program demonstrates different mathematical operations
#include <iostream.h>
int main()
{
float result;
result = 1.0 + 2.0 * 3.0 / 4.0;
cout << '\n' << result;
result = 1.0 / 2.0 + 3.0;
cout << '\n' << result;
result = (1.0 + 2.0) / 3.0;
cout << '\n' << result;
result = (1.0 + 2.0 / 3.0) + 4.0;
cout << '\n' << result;
return 0;
}
This Program demonstrates the IF conditional statement to check the condition
#include <iostream.h>
int main()
{
int your_number;
cout << "Enter a whole number: ";
cin >> your_number;
if (your_number % 2 == 0)
cout << "\nYour number is even\n";
if (your_number % 2 != 0)
{
cout << "Your number is odd.\n";
}
cout << "That's all!\n";
return 0;
}
This Program demonstrates IF….ELSE conditional statement
#include <iostream.h>
int main()
{
int your_number;
cout << "Enter a whole number: ";
cin >> your_number;
if (your_number % 2 == 0)
cout << "Your number is even\n";
else
{
cout << "Your number is odd.\n";
}
cout << "That's all!\n";
return 0;
}
This Program demonstrates the IF….ELSEIF nested conditional statements
#include <conio.h>
#include <iostream.h>
#include <ctype.h>
int main()
{
char cmd;
cout << "Chart desired: Pie Bar Scatter Line Three-D";
cout << "\n Press first letter of the chart you want: ";
cmd = toupper(getch());
cout << '\n';
if (cmd == 'P')
cout << "Doing pie chart\n";
else if (cmd == 'B')
cout << "Doing bar chart\n";
else if (cmd == 'S')
cout << "Doing scatter chart\n";
else if (cmd == 'L')
cout << "Doing line chart\n";
else if (cmd == 'T')
cout << "Doing 3-D chart\n";
else cout << "Invalid choice.\n";
return 0;
}
No comments:
Post a Comment