20F-0531 ITC Today's Lab
20F-0531 ITC Today's Lab
#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;
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;
}