0% found this document useful (0 votes)
3 views

Practical Copy Five Programs

The document contains multiple C++ programs demonstrating various concepts such as checking for Armstrong numbers, prime numbers, summing digits, and basic class inheritance. Each program prompts the user for input and performs specific calculations or displays results based on that input. The code includes basic input/output operations and uses standard libraries for functionality.

Uploaded by

guddurawani89419
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Practical Copy Five Programs

The document contains multiple C++ programs demonstrating various concepts such as checking for Armstrong numbers, prime numbers, summing digits, and basic class inheritance. Each program prompts the user for input and performs specific calculations or displays results based on that input. The code includes basic input/output operations and uses standard libraries for functionality.

Uploaded by

guddurawani89419
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

// Armstrong Number

#include<iostream.h>
#include<conio.h>

void main()
{

int n, org , i, sum, rem;

clrscr();

cout<<"\n Enter the number ";


cin>>n;

org = n;
sum = 0;

while(org>0)
{
rem = org%10;
sum = sum + rem*rem*rem;
org = org/10;
}

if (sum == n)
cout<<"\n The number is armstrong number ";

else
cout<<"\n The number is not an armstrong";

getch();
}
#include <iostream.h>

void main()
{
int num, i, flag = 0;

// Input number from user


cout<<"\n Enter a number: ");
cin>>num;

// Check if the number is prime


if (num <= 1)
{
cout<<"\n The number is not a prime number.";
}
else
{
for (i = 2; i <= num / 2; i++)
{
if (num % i == 0)
{
flag = 1;
break;
}
}

if (flag == 0)
cout<<"\n The number is a prime number.";
else
cout<<"The number is not a prime number.";
}
}
#include <conio.h>
#include <iostream.h>

void main()
{
clrscr(); // Clear screen

int num, sum = 0, digit;

cout << "Enter a number: ";


cin >> num;

while (num > 0) {


digit = num % 10; // Extract the last digit
sum += digit; // Add digit to sum
num = num / 10; // Remove the last digit
}

cout << "Sum of digits: " << sum;

getch(); // Wait for key press


}

#include <iostream.h>
#include <conio.h>

// Base class (Parent)


class Parent
{
public:
int a;

void getData()
{
cout << "Enter a number: ";
cin >> a;
}

void showData()
{
cout << "Value of a: " << a << endl;
}
};

// Derived class (Child) - inherits Parent class

class Child : public Parent


{
public:
void square()
{
cout << "Square of " << a << " is: " << (a * a) << endl;
}
};

void main()
{
clrscr();
Child obj; // Object of derived class
obj.getData();
obj.showData();
obj.square();
getch();
}

#include <iostream.h>
#include <conio.h>

void main()
{
clrscr();

int arr[5], i;

// Input: Taking array elements from user


cout << "Enter 5 numbers: ";
for (i = 0; i < 5; i++)
{
cin >> arr[i];
}

// Output: Displaying array elements


cout << "You entered: ";
for (i = 0; i < 5; i++)
{
cout << arr[i] << " ";
}

getch();
}

You might also like