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

Board CPP program

The document contains a series of C++ programming tasks, including programs to check for Armstrong numbers, calculate averages, generate Fibonacci series, compute factorials, reverse strings, find the smallest integer, and check for prime numbers. Each task is accompanied by sample code demonstrating the implementation. The document also mentions the use of object-oriented programming techniques for some tasks.

Uploaded by

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

Board CPP program

The document contains a series of C++ programming tasks, including programs to check for Armstrong numbers, calculate averages, generate Fibonacci series, compute factorials, reverse strings, find the smallest integer, and check for prime numbers. Each task is accompanied by sample code demonstrating the implementation. The document also mentions the use of object-oriented programming techniques for some tasks.

Uploaded by

Jash Mehta
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Write a C++ program to find whether the entered number is an Armstrong number
or not. [Mar-2023]

#include<iostream.h>
#include<conio.h>
void main()
{
int n,dn,t,d;
clrscr();
cout<<”\n Enter number:”;
cin>>n;
dn=n;
t=0;
while(dn!=0)
{
d=dn%10;
t=t+(d*d*d);
dn=dn/10;
}
if(n==t)
cout<<”\n”<<n<<” is armstrong number.”;
else
cout<<”\n<<n<<” is not an armstrong number.”;
getch();
}
2. Implement Class average that accepts values of three float variables, another
function print() average of three numbers. [Mar-2023]

#include<iostream.h>
#include<conio.h>
class average
{
public:
float a,b,c,avg;
average()
{
cout<<”\n Enter three numbers:”;
cin>>a>>b>>c;
}
void print()
{
avg=(a+b+c)/3.0;
cout<<”\n Average=”<<avg;
}
};
void main()
{
clrscr();
average x;
x.print();
getch();
}
3. Write a C++ program which finds a fibonacci series of “n” terms. [Mar-2023]

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int f0=0,f1=1,f,n;
cout<<”\n Enter number of terms:”;
cin>>n;
cout<<”\n fibonacci series:”;
cout<<”\n”<<f0<<”\n”<<f1;
for(int i=2;i<=n;i++)
{
f=f0+f1;
cout<<”\n”<<f;
f0=f1;
f1=f;
}
getch();
}
4. Write a C++ program to find the factorial of a number during execution by using a
constructor function. [Mar-2023]

#include<iostream.h>
#include<conio.h>
class fact
{
int n,i,c;
public:
fact()
{
cout<<”\n Enter number:”;
cin>>n;
f=1;
for(i=1;i<=n;i++)
{
f=f*i;
}
cout<<”\n Factorial of number=”<<f;
}
};
void main()
{
clrscr();
fact x;
getch();
}
5. Write a C++ program to accept a sentence (max 50 characters) and print the
sentence in reverse. [Mar-2019]

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char str[50], rev[50];
int len,i,k;
cout<<"Enter string:";
cin>>str;
for(i=0;str[i]!='\0';i++)
len=i+1;
cout<<len;
len--;
for(k=0;len>=0;len--,k++)
rev[k]=str[len];
rev[k]='\0';
cout<<"reverse string is="<<rev;
getch();
}

6. Write a function to accept four integers. Find the smallest integer and print it. [Mar-2019]
[Mar-2018]
7. Write a C++ program to find the smallest in any array of 10 floats using a pointer. [Mar-
2019]
8. Write a class based program in C++ to find the area of a triangle. [Mar-2019]
9. Write a C++ program to accept an integer number and test whether it is prime or not.
[Mar-2018]
#include <iostream.h>
#include<conio.h>
void main()
{
clrscr();
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";
getch();
}

10. Write a program in C++ using OOP technique to compute the circumference of a circle.
[Mar-2018]
11. Write an OOP in C++ to read an integer number and find sum of digits of integer. [Mar-
2018]

You might also like