Sie sind auf Seite 1von 8

1

Barani Institute Sahiwal

Programing Fundamentals
Lab Manual
1. C++ "Hello, World!" Program
2. C++ Program to Print Number Entered by User
3. C++ Program to Add Two Numbers
4. C++ Program to Find Quotient and Remainder
5. C++ Program to Find Size of int, float, double and char in Your System
6. C++ Program to Swap Two Numbers
7. C++ Program to Reverse Number 1234 to 4321
8. C++ Program to Check Whether Number is Even or Odd
9. C++ Program to Check Whether a character is Vowel or Consonant.
10. C++ Program to Find Largest Number Among Three Numbers
11. C++ Program to Find Grades
12. C++ Program to Find All Roots of a Quadratic Equation
13. C++ Program to Calculate Sum of Natural Numbers
14. C++ Program to Check Leap Year
15. C++ Program to Find Factorial
16. C++ Program to Generate Multiplication Table
17. C++ Program to Display Fibonacci Series
18. C++ Program to Find GCD
19. C++ Program to Find LCM
20. C++ Program to Reverse a Number
21. C++ Program to Calculate Power of a Number
22. Increment ++ and Decrement -- Operator Overloading in C++ Programming
23. C++ Program to Subtract Complex Number Using Operator Overloading
24. C++ Program to Find ASCII Value of a Character
25. C++ Program to Multiply two Numbers
26. C++ Program to Check Whether a Number is Palindrome or Not
27. C++ Program to Check Whether a Number is Prime or Not
28. C++ Program to Display Prime Numbers Between Two Intervals

Prof. Mumtaz Ahmad mumtaz.ahmadswl@gmail.com 0301-6927006


2
Barani Institute Sahiwal

29. C++ Program to Check Armstrong Number


30. C++ Program to Display Armstrong Number Between Two Intervals
31. C++ Program to Display Factors of a Number
32. C++ Programs To Create Pyramid and Pattern
33. C++ Program to Make a Simple Calculator to Add, Subtract, Multiply or Divide Using
switch...case
34. C++ Program to Display Prime Numbers Between Two Intervals Using Functions
35. C++ Program to Check Prime Number By Creating a Function
36. C++ Program to Check Whether a Number can be Express as Sum of Two Prime
Numbers
37. C++ program to Find Sum of Natural Numbers using Recursion
38. C++ program to Calculate Factorial of a Number Using Recursion
39. C++ Program to Find G.C.D Using Recursion
40. C++ Program to Convert Binary Number to Decimal and vice-versa
41. C++ Program to Convert Octal Number to Decimal and vice-versa
42. C++ Program to Convert Binary Number to Octal and vice-versa
43. C++ program to Reverse a Sentence Using Recursion
44. C++ Program to Calculate Power Using Recursion
45. C++ Program to Calculate Average of Numbers Using Arrays
46. C++ Program to Find Largest Element of an Array
47. C++ Program to Calculate Standard Deviation
48. C++ Program to Add Two Matrix Using Multi-dimensional Arrays
49. C++ Program to Multiply Two Matrix Using Multi-dimensional Arrays
50. C++ Program to Find Transpose of a Matrix
51. C++ Program to Multiply two Matrices by Passing Matrix to Function
52. C++ Program to Access Elements of an Array Using Pointer
53. C++ Program to Swap Numbers in Cyclic Order Using Call by Reference
54. C++ Program to Find the Frequency of Characters in a String
55. C++ Program to Find the Number of Vowels, Consonants, Digits and White Spaces in a
String
56. C++ Program to Remove all Characters in a String Except Alphabets.

Prof. Mumtaz Ahmad mumtaz.ahmadswl@gmail.com 0301-6927006


3
Barani Institute Sahiwal

57. C++ Program to Find the Length of a String


58. C++ Program to Concatenate Two Strings
59. C++ Program to Copy Strings
60. C++ Program to Sort Elements in Lexicographical Order (Dictionary Order)
61. C++ Program to Store Information of a Student in a Structure
62. C++ Program to Add Two Distances (in inch-feet) System Using Structures
63. C++ Program to Add Complex Numbers by Passing Structure to a Function
64. C++ Program to Calculate Difference Between Two Time Period
65. C++ Program to Store and Display Information Using Structure

Prof. Mumtaz Ahmad mumtaz.ahmadswl@gmail.com 0301-6927006


4
Barani Institute Sahiwal

1. Hello World Program


#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!";
return 0;
}

2. Print Number Entered by User


#include <iostream>
using namespace std;
int main()
{
int number;
cout << "Enter an integer: ";
cin >> number;
cout << "You entered " << number;
return 0;
}

3. Program to Add Two Integers


#include <iostream>
using namespace std;
int main()
{ int a, b, sum;
cout << "Enter two integers: ";
cin >> a >> b;
sum= a + b;
cout << a << " + " << b << " = " << sum;
}

Prof. Mumtaz Ahmad mumtaz.ahmadswl@gmail.com 0301-6927006


5
Barani Institute Sahiwal

4. Compute Quotient and Remainder


#include <iostream>
using namespace std;
int main()
{
int divisor, dividend, quotient, remainder;
cout << "Enter dividend: ";
cin >> dividend;
cout << "Enter divisor: ";
cin >> divisor;
quotient = dividend / divisor;
remainder = dividend % divisor;
cout << "Quotient = " << quotient << endl;
cout << "Remainder = " << remainder;
}

5. Find the Size of all Datatypes


#include <iostream>
using namespace std;
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;
}

6. Swap Numbers (Using Temporary Variable)


#include <iostream>
using namespace std;
int main()
{

Prof. Mumtaz Ahmad mumtaz.ahmadswl@gmail.com 0301-6927006


6
Barani Institute Sahiwal

int a = 5, b = 10, temp;


cout << "Before swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
temp = a;
a = b;
b = temp;
cout << "\nAfter swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
}

7. Swap Numbers Without Using Temporary Variables


#include <iostream>
using namespace std;
int main()
{
int a = 5, b = 10;
cout << "Before swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
a = a + b;
b = a - b;
a = a - b;
cout << "\nAfter swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
}

8. Reverse Numbers 12345 to 54321


#include <iostream>
using namespace std;
int main()
{
int a,b,c,d,n;

Prof. Mumtaz Ahmad mumtaz.ahmadswl@gmail.com 0301-6927006


7
Barani Institute Sahiwal

cout<< “\nPlease enter a number of five digit = ”;


cin>>n;
a = n / 10000;
n = n % 10000;
b = n / 1000;
n = n % 1000;
c = n / 100;
n = n % 100;
d = n / 10;
n = n % 10;
cout<< n << d << c << b << a ;
}

9. Check Whether Number is Even or Odd using if else


#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter an integer: ";
cin >> n;
if ( n % 2 == 0)
cout << n << " is even.";
else
cout << n << " is odd.";
}

10. Check Whether Number is Even or Odd using ternary operators


#include <iostream>
using namespace std;
int main()

Prof. Mumtaz Ahmad mumtaz.ahmadswl@gmail.com 0301-6927006


8
Barani Institute Sahiwal

{
int n;
cout << "Enter an integer: ";
cin >> n;
(n % 2 == 0) ? cout << n << " is even." : cout << n << " is
odd.";
}

11. Find the Greatest Numbers Among Three Numbers


#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout << "Please enter three numbers = ";
cin >> a >> b >> c;
if (a > b)
if (b > c)
cout<< “A is greater”;
else
if(b > c)
cout<< “B is greater”;
else
cout<< “C is greater”;
}

Prof. Mumtaz Ahmad mumtaz.ahmadswl@gmail.com 0301-6927006

Das könnte Ihnen auch gefallen