Programs
Programs
2. Write a C++ program to find the best CE score from the three given scores (PRACTICAL).
Code
#include <iostream>
using namespace std;
int main()
{
short int ce1, ce2, ce3, final_ce;
cout<<"Enter three CE scores: ";
cin>>ce1>>ce2>>ce3;
if (ce1>ce2)
final_ce=ce1;//Will be executed, if the condition is true
else
final_ce=ce2;//Will be executed, if the condition is false
if (ce3>final_ce)
final_ce=ce3; //No else block for this if
cout<<"Final CE Score is "<<final_ce;
return 0;
}
3. Write a C++ program to check whether the character is uppercase letter, lowercase
letter, digit or other characters.
Code
#include <iostream>
using namespace std;
int main()
{
char ch;
cout<<"Enter a character: ";
cin>>ch;
if (ch>='A' && ch<='Z')
cout<<"Uppercase letter";
else if (ch>='a' && ch<='z')
cout<<"Lowercase letter";
else if (ch>='0' && ch<='9')
cout<<"Digit";
else
cout<<"Other character";
return 0;
}
10. Write a C++ program to display all palindrome numbers between 100 and 200.
Code
#include<iostream>
using namespace std;
int main( )
{
int n, rev, t, d;
cout<<"Palindrome Numbers between 100 and 200\n ";
for(n=100; n<=200; n++)
{
rev=0;
t=n;
while(t>0)
{
d=t%10;
rev=(rev*10)+d;
t=t/10;
}
if(rev==n)
cout<<n<<'\t';
}
return 0;
}
11. Write a C++ program to check whether a given number is Armstrong number or not.
Code
#include<iostream>
using namespace std;
int main()
{
int n,t,d,s;
cout<<"Enter a Number : ";
cin>>n;
t=n;
s=0;
while(n!=0)
{
d=n%10;
s=s+(d*d*d);
n=n/10;
}
if(t==s)
cout<<t<<" is an Armstrong Number";
else
cout<<t<<" is not an Armstrong Number";
return 0;
}
12. Write a C++ program to display all Armstrong numbers below 1000.
Code
# include<iostream>
using namespace std;
int main()
{
int i,s,n,d;
cout<<"Armstrong Numbers below 1000\n";
for(i=1;i<1000;i++)
{
s=0;
n=i;
while(n!=0)
{
d=n%10;
s=s+(d*d*d);
n=n/10;
}
if(i==s) cout<<i<<"\t";
}
return 0;
}
13. Write a C++ program to display all perfect numbers below 1000.
Code
#include <iostream>
using namespace std;
int main()
{
int n,i,sum;
cout<<"Perfect Numbers below 1000\n";
for(n=1;n<1000;n++)
{
sum=0;
for(i=1;i<n;i++)
{
if(n%i==0)
sum=sum+i;
}
if(sum==n)
cout << n << "\n";
}
return 0;
}
15. Write a C++ program to prepare electricity bill for a group of consumers.
The previous meter reading and current reading are the inputs. The payable
amount is to be calculated using the following criteria:
Up to 300 units :
Rs. 5.00/- per unit
Up to 350 units :
Rs. 5.70/- per unit
Up to 400 units :
Rs. 6.10/- per unit
Up to 500 units :
Rs. 6.70/- per unit
Above 500 units :
Rs. 7.50/- per unit
The program should provide facility to input the details of any number of
consumers as the user wants.
Code
#include <iostream>
using namespace std;
int main()
{
float previous, current, units, charge, t ;
char ch;
start:
cout << "Enter the previous meter reading : ";
cin>>previous;
cout << "Enter the current meter reading : ";
cin >>current;
units=current-previous;
if(units<=300)
charge=units*5.00;
else if(units<=350)
{
t=units-300;
charge=300*5.00+t*5.70;
}
else if(units<=400)
{
t=units-350;
charge=300*5.00+50*5.70+t*6.10;
}
else if(units<=500)
{
t=units-400;
charge=300*5.00+50*5.70+50*6.10+t*6.70;
}
else
{
t=units-500;
charge=300*5.00+50*5.70+50*6.10+100*6.70+t*7.50;
}
cout<<"Units consumed :"<<units;
cout<<"\nCharge : "<<charge;
cout<<"\nAny more consumer(Y/N)?";
cin>>ch;
if(ch=='Y'||ch=='y')
goto start;
return 0;
}