0% found this document useful (0 votes)
28 views6 pages

20F-0531 ITC Today's Lab

Uploaded by

Zain Mehmood
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)
28 views6 pages

20F-0531 ITC Today's Lab

Uploaded by

Zain Mehmood
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/ 6

Task 1(a):

#include <iostream>
using namespace std;
void Even_numbers(int a);
int main()
{
int Z = 100;
Even_numbers(Z);
return 0;
}
void Even_numbers(int a)
{
cout << " EVEN NUMBER ARE = " << endl;
for (int i = 1; i <= a; i++)
{
if (i % 2 == 0)
cout << i << " ";
}
}

Result:

Task 1(b):
#include <iostream>
using namespace std;
void Divider(int z, int a);
int main()
{
int z;
int a;
cout << " Enter value of numerator z = ";
cin >> z;
cout << " Enter value of denominator a = ";
cin >> a;
Divider(z, a);
return 0;
}
void Divider(int z, int a)
{
if (a == 0)
cout << "INFINITY DIVISION NOT PERFORMED\n";
else
cout << "Result = " << z / a << endl;
}

Result:
Task 2:
#include <iostream>
using namespace std;
void Armstrong(int n);

int main() {
int f;
int c;
cout << " How many numbers do you want to enter to check either they are ARMSTRONG or NOT = ";
cin >> c;
for (int i = 1; i <= c; i++) {
cout << "Enter a positive number having three integers = ";
cin >> f;
Armstrong(f);
cout << endl;
}
return 0;
}

void Armstrong(int f) {
int x, sum = 0, y;
bool isArm;

x = f;
while (x != 0) {
y = x % 10;
sum = sum + (y*y*y);
x = x / 10;
}
if (sum == f) {
isArm = true;
}
else {
isArm = false;
}

if (isArm == true)
cout << f << " is an Armstrong number.";
else
cout << f << " is not an Armstrong number.";
}

Result:
Task 3:
# include <iostream>
using namespace std;

void showChoice(int n, int n2, char c);


int main()
{
int a;
int b;
char c;
cout << " Enter the value integer 1 :";
cin >> a;
cout << " Enter the value integer 2 :";
cin >> b;
cout << " Enter the operand(+ ,- ,/ ,*) :";
cin >> c;
showChoice(a, b, c);
return 0;
}
void showChoice(int n, int n2, char c) {
switch (c)
{
case '+':
cout << "SUM =" << n + n2;
break;

case '-':
cout << "Subtracrion =" << n - n2;
break;

case '*':
cout << "Multiplication =" << n*n2;
break;

case '/':
if (n2 == 0) {
cout << "Infinity DIVISION NOT PERFORMED";
break;
}
cout << " Division =" << n / n2;
break;

default:
cout << "Enter the operator given in choice";
break;
}

Result:

Task 4(a):
#include <iostream>
using namespace std;
void fibonacci(int a);
int main()
{
int a = 25;
fibonacci(a);
return 0;
}
void fibonacci(int a)
{
int i, j = 0, b = 1, x;
cout << "Required Fibonacci series is" << endl;
for (i = 1; i <= a; ++i)
{
cout << j << " ";
x = j + b;
j = b;
b = x;
cout << endl;
}
}

Result:
Task 4(b):
#include <iostream>
using namespace std;
int Prime(int x);
int main()
{
bool y;
int x = 20;
for (int n = 2; n < x; n++) {
y = Prime(n);
if (y == true)
cout << n << " ";
}
return 0;
}
intPrime(int n); {
bool Prime = true;
for (inti = 2; i <= n / 2; i++) {
if (x%i == 0) {
Prime = false;
break;
}
}
return Prime;
}

You might also like