0% found this document useful (0 votes)
4 views8 pages

CP Lab 03

This document is a lab report from the Military College of Signals, detailing practical implementations of various programming tasks in C++. It includes group member names, rubrics for evaluation, and several C++ programs that demonstrate concepts such as Fibonacci sequences, factorial calculations, pyramid patterns, prime number checks, GCD calculations, and binary conversions. The report is submitted for evaluation on March 13, 2025.

Uploaded by

azizrashid848
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

CP Lab 03

This document is a lab report from the Military College of Signals, detailing practical implementations of various programming tasks in C++. It includes group member names, rubrics for evaluation, and several C++ programs that demonstrate concepts such as Fibonacci sequences, factorial calculations, pyramid patterns, prime number checks, GCD calculations, and binary conversions. The report is submitted for evaluation on March 13, 2025.

Uploaded by

azizrashid848
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Military College of

Signals
National University of
Sciences & Technology

COMPUTER PROGRAMMING, LAB


Submitted to: Maj Sarmad Idress, Lab Engr Ibtisam Anwar

Lab Report Number


03

Submission Date: 13 Mar 2025

Section: BEE-61 A

Group Members:

S. No Names

1. Wania Ali

2. Rashid Aziz

3. Capt Hasnain Asghar

4. Capt Muhammad Umair Nasir


RUBRICS for Practical Implementation

Student Wania Ali Rashid Aziz Capt Hasnain Capt Umair


Name
R1 (3)

R2 (3)

R3 (3)

R4 (3)

R5 (3)

Total (15)

RUBRICS for Design presentation (Report) and viva

R1 (3)

R2 (3)

R3 (3)

R4 (3)

Total(12)

Grand Total (27)


Lab # 02
Getting Started with C++
Take number from user and print Fibonacci sequence up to that no.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int num, a = 0, b = 1, nextTerm = 0;

cout << "Enter a number: ";


cin >> num;

cout << "Fibonacci sequence up to " << num << ": ";

while (nextTerm <= num) {


cout << nextTerm << " ";
a = b;
b = nextTerm;
nextTerm = a + b;
}
return 0;
#include <iostream>

Write a program that calculates the factorial of a given number using a loop.
#include <iostream>

#include <vector>

using namespace std;

int main(){

int num, fact=1;

cout<<"Enter any number: ";

cin>>num;

for(int i=1; i<=num; i++){

fact = fact * i;

cout<<"Factorial of "<<num<<" is: "<<fact<<".";

return 0;}
#include <iostream>

Write a program that prints a pyramid pattern using nested loops.

using namespace std;


int main()
{ int rows;
cout << "Enter the number of rows: ";
cin >> rows;
for (int i = 1; i <= rows; i++) {
// Print spaces
for (int j = 1; j <= rows - i; j++) {
cout << " "; }
for (int k = 1; k <= (2 * i - 1); k++) {
cout << "*";
}
cout << endl;
}return 0;
}
#include <iostream>

Write a program that determines if a given number is a prime number or not.


#include <iostream>
using namespace std; int
main()
{ int num, count=0;
cout<<"Enter any number: ";
cin>>num;
for(int i=1; i<=num; i++){
if(num % i == 0){
count++;
} }
if(count == 2){
cout<<num<<" is Prime."; }
else
{
cout<<num<<" is not Prime.";
}return 0;
}
#include <iostream>

Program that finds greatest common divisor (GCD) of two numbers using a loop.

#include <cctype> // For toupper()


using namespace std; int main()
{ int num1, num2, gcd;
cout << "Enter two numbers: ";
cin >> num1 >> num2;
for (int i = 1; i <= num1 && i <= num2; i++) {
if (num1 % i == 0 && num2 % i == 0) {
gcd = i; // Update gcd if 'i' divides both numbers
}}
cout << "GCD of " << num1 << " and " << num2 << " is: " << gcd <<
endl; return 0; }

Program that converts a decimal number into its binary equivalent.


#include <iostream>
#include <cctype> // For tolower()
using namespace std; int main() {
#include <iostream>

int decimalNum, binaryNum[32], i = 0;


cout << "Enter a decimal number: ";
cin >> decimalNum;
if (decimalNum == 0) {
cout << "Binary equivalent: 0" << endl;
return 0; }
while (decimalNum > 0) {
binaryNum[i] = decimalNum % 2;
decimalNum /= 2; i++; }
cout << "Binary equivalent: ";
for (int j = i - 1; j >= 0; j--) { cout << binaryNum[j]; }
cout << endl; return 0; }

You might also like