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

Document 52

The document contains a series of programming tasks written in C++ by a student named Halema Daood. Each task demonstrates different programming concepts such as loops, conditionals, and functions, including generating Fibonacci numbers, calculating factorials, and counting digits in a number. The code snippets are structured as separate tasks with corresponding outputs and user prompts.

Uploaded by

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

Document 52

The document contains a series of programming tasks written in C++ by a student named Halema Daood. Each task demonstrates different programming concepts such as loops, conditionals, and functions, including generating Fibonacci numbers, calculating factorials, and counting digits in a number. The code snippets are structured as separate tasks with corresponding outputs and user prompts.

Uploaded by

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

NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES

NAME:HALEMA DAOOD

ROLL NO:24F-6133

SECTION:BSEE-1B

TASK 01
#include <iostream>

using namespace std;

int main()

int i = 2;

while (i <= 20)

cout << i;

cout << “/n”;

i = i + 2;

system(“pause”);

TASK 02
#include <iostream>

using namespace std;

int main()

int i;
for (i = 10; i <= 60; i++)

if (i % 2==0)

cout << i;

cout << “/n”;

system(“pause”);

TASK 03
#include <iostream>

using namespace std;


int main() {

int n;

cout << "Enter the number of Fibonacci numbers to generate:

";

cin >> n;

int a = 1, b = 2, next;

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

if (i == 1) {

cout << a << " ";

continue;

if (i == 2) {

cout << b << " ";

continue;

next = a + b;

cout << next << " ";

a = b;

b = next;

cout << endl;

return 0;

TASK 04
#include <iostream>

using namespace std;

int main()

int n;

int factorial = 1;
cout << “enter a positive integer”;

cin >> n;

if (n <0) {

cout << “factorial is not defimed for negative numbers”<< endl;

else {

int i = 1;

while (i <= 1) {

factorial *= i;

i++;

cout << “factorial is”<<factorial << endl;

system(“pause”);

TASK 05
#include <iostream>

using namespace std;

int main()

int number;

cout << "Enter an integer: ";

cin >> number;

if (number == 0)

cout << "The number has 1 digit." << endl;

return 0;

}
if (number == 0)

cout << "The number has 1 digit." << endl;

return 0;

int digit_count = 0;

while (number > 0)

number = number / 10;

digit_count++;

cout << "The number has " << digit_count << " digits." <<

endl;

return 0;

TASK 06
#include <iostream>

using namespace std;

int main()

int num = 5;

int guess;
cout << "Guess the number (between 1 and 10): ";

while (true) {

cin >> guess;

if (guess == num) {

cout << "Correct! You guessed the number.\n";

break;

else

cout << "Wrong! Try again: ";

return 0;

TASK 07
#include <iostream>

using namespace std;

int main()

int yearsWorked[] = { 3, 7, 5, 8, 2, 10, 4 };

int numberOfEmployees = sizeof(yearsWorked) /

sizeof(yearsWorked[0]);
for (int i = 0; i < numberOfEmployees; i++)

if (yearsWorked[i] > 5)

cout << "Employee " << i + 1 << " (worked " <<

yearsWorked[i]

<< " years) qualifies for the 10% bonus." <<

endl;

else

cout << "Employee " << i + 1 << " (worked " <<

yearsWorked[i]

<< " years) does NOT qualify for the 10% bonus."

<< endl;

return 0;

You might also like