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

C++ programs

This file is c++ .class 12 all the students help for this file

Uploaded by

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

C++ programs

This file is c++ .class 12 all the students help for this file

Uploaded by

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

ARMSTRONG NUMBER

#include <iostream>
using namespace std;
class Test
{
public:
int checkArmstrong(int x)
{
int r,num=0;
while (x>0)
{
r=x%10;
num=num+rrr;
x=x/10;
}
return num;
}
};
int main()
{
int x,arm;
cout << "enter a number:";
cin>>x;
Test obj;
arm=obj.checkArmstrong(x);
if(arm==x)
{
cout<<"Number is armstrong";
}else
{
cout<<"Number is not armstrong";
}
return 0;
}
SPY NUMBER

#include <iostream>
using namespace std;

bool checkSpy(int number) {


int sum = 0, mul = 1, rem;

while (number > 0) {


rem = number % 10;
sum += rem;
mul *= rem;
number = number / 10;
}
if (sum == mul) {
return true;
}
else {
return false;
}
}

int main() {
int number;

cout << "Enter a number to check for spy number: ";


cin >> number;

if (checkSpy(number)) {
cout << number << " is a spy number";
} else {
cout << number << " is not a spy number";
}

return 0;
}
PALINDROME NUMBER
#include <iostream>
using namespace std;

int main(){
int x, temp, r, rev = 0;
cout << "Enter number to check palindrome or not:" << endl;
cin >> x;
temp = x;

while (x != 0) {
r = x % 10;
rev = rev * 10 + r;
x = x / 10;
}

if (temp == rev) {
cout << temp << " is palindrome
number" << endl;
} else {
cout << temp << " is not palindrome
number" << endl;
}

return 0;
}
PERFECT NUMBER

#include <iostream>
using namespace std;

int main() {
int number, sum = 0;

cout << "Enter a number to check for perfect: ";


cin >> number;

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


if (number % i == 0) {
sum = sum + i;
}
}

if (sum == number) {
cout << number << " is a perfect number";
}
else {
cout << number << " is not a perfect number";
}

return 0;
}
PRIME NUMBER
#include <iostream>
using namespace std;

int main() {

int i, n;
bool is_prime = true;

cout << "Enter a positive integer: ";


cin >> n;

// 0 and 1 are not prime numbers


if (n == 0 || n == 1) {
is_prime = false;
}

// loop to check if n is prime


for (i = 2; i <= n/2; ++i) {
if (n % i == 0) {
is_prime = false;
break;
}
}

if (is_prime)
cout << n << " is a prime number";
else
cout << n << " is not a prime number";

return 0;
}
BUZZ NUMBER

#include <iostream>

using namespace std;

int main()
{
int n;
cout<<"Enter a number: ";
cin>>n;
if(n%7==0 || n%10==7)
{
cout<<"Buzz number";
}
else
{
cout<<"Not a buzz number";
}
return 0;
}
NEON NUMBER

#include <iostream>
using namespace std;

int main()
{
int num;

cout << "Enter the number: ";


cin >> num;

int square = num * num;


int sum = 0;

while (square > 0)


{
int lastDigit = square % 10;
sum = sum + lastDigit;
square = square / 10;
}

if (sum == num)
cout << num << " is a Neon number";
else
cout << num << " is NOT a Neon number";

return 0;

}
FIBONACCI SERIES

#include <iostream>
using namespace std;

int main() {
int n, t1 = 0, t2 = 1, nextTerm = 0;

cout << "Enter the number of terms:


";
cin >> n;

cout << "Fibonacci Series: ";

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


// Prints the first two terms.
if(i == 1) {
cout << t1 << ", ";
continue;
}
if(i == 2) {
cout << t2 << ", ";
continue;
}
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;

cout << nextTerm << ", ";


}
return 0;
}
AREA AND CIRCUMFERENCE OF CIRCLE

#include<iostream>
using namespace std;
int main()
{
float r, area, circum;
cout<<"Enter the Radius of Circle: ";
cin>>r;
area = 3.14*r*r;
cout<<"\nArea of Circle = "<<area;
cout<<endl;
circum = 2*3.14*r;
cout<<"\nCircumference of Circle = "<<circum;
cout<<endl;
return 0;
}
LEAP YEAR

#include <iostream>
using namespace std;

int main() {

int year;
cout << "Enter a year: ";
cin >> year;

// leap year if perfectly divisible by 400


if (year % 400 == 0) {
cout << year << " is a leap year.";
}
// not a leap year if divisible by 100
// but not divisible by 400
else if (year % 100 == 0) {
cout << year << " is not a leap year.";
}
// leap year if not divisible by 100
// but divisible by 4
else if (year % 4 == 0) {
cout << year << " is a leap year.";
}
// all other years are not leap years
else {
cout << year << " is not a leap year.";
}

return 0;
}

You might also like