Board CPP program
Board CPP program
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;
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]