Vous êtes sur la page 1sur 6

1 If statements

Two numbers are entered through the keyboard. Write a program to find the value of one number raised to the power of another.

#include<iostream.h> #include<conio.h> int main() { clrscr(); int n,p,r=1; cout<<"Enter the base number and exponent "; cin>>n>>p; for(int i=1;i<=p;i++) r=r*n; cout<<"Result :"<<r; getch(); return 0; }
Write a program to reverse any given integer number.

#include<iostream.h> #include<conio.h> int main() { clrscr(); int n,t,r,rev=0; cout<<"Enter any number "; cin>>n; t=n; while(t>0) { r=t%10; t=t/10; rev=rev*10+r; } cout<<"Reverse of number "<<n<<" is "<<rev; getch(); return 0; }
Write a program to sum of digits of given integer number.

#include<iostream.h> #include<conio.h> int main() { clrscr();

2
int n,t,r,sum=0; cout<<"Enter any number "; cin>>n; t=n; while(t>0) { r=t%10; sum+=r; t=t/10; } cout<<"Sum of digits of number "<<n<<" is "<<sum; getch(); return 0; }
Write a program to check given number is prime or not.

#include<iostream.h> #include<conio.h> int main() { clrscr(); int n,flag=0; cout<<"Enter any number "; cin>>n; for(int i=2;i<n;i++) { if(n%i==0) { flag=1; break; } } if(flag==0 && n>1) cout<<"Number is prime"; else cout<<"Number is not prime"; getch(); return 0; } #include<iostream.h> #include<conio.h> int main() { clrscr(); int n, max=0, min=32767; char choice; do { cout<<"Enter number ";

3
cin>>n; if(n>max) max=n; if(n<min) min=n; cout<<"Do you want to Continue(y/n)? "; cin>>choice; }while(choice=='y' || choice=='Y'); cout<<"Maximum Number :"<<max<<"\nMinimum Number :"<<min; getch(); return 0; }

If Statements
Find the absolute value of a number entered by the user.

#include<iostream.h> #include<conio.h> void main() { clrscr(); int a; cout<<"Enter any number:"; cin>>a; if(a>0) cout<<"The absolute value of number is:"<<a; else cout<<"The absolute value of number is:"<<-(a); getch(); }

Write a program to calculate the total expenses. Quantity and price per item are input by the user and discount of 10% is offered if the expense is more than 5000.

#include<iostream.h> #include<conio.h> void main() { clrscr(); int totalexp, qty, price, discount;

4
cout<<"Enter quantity:"; cin>>qty; cout<<"Enter price:"; cin>>price; totalexp=qty*price; if(totalexp>5000) { discount=(totalexp*0.1); totalexp=totalexp-discount; } cout<<"Total Expense is getch(); Rs. "<<totalexp;

In a company an employee is paid as under: If his basic salary is less than Rs. 1500, then HRA = 10% of basic salary and DA = 90% of basic salary. If his salary is either equal to or above Rs. 1500, then HRA = Rs. 500 and DA = 98% of basic salary. If the employee's salary is input by the user write a program to find his gross salary.

#include<iostream.h> #include<conio.h> int main() { clrscr(); float basic_salary, gross_salary; cout<<"Enter basic salary of Employee : "; cin>>basic_salary; if (basic_salary<1500) gross_salary=basic_salary+(0.1*basic_salary)+(0.9*basic_salary); else gross_salary=basic_salary+500+(0.98*basic_salary); cout<<"Gross salary is : "<<gross_salary; getch(); return 0; }
Write a program to calculate the monthly telephone bills as per the following rule: Minimum Rs. 200 for upto 100 calls. Plus Rs. 0.60 per call for next 50 calls. Plus Rs. 0.50 per call for next 50 calls. Plus Rs. 0.40 per call for any call beyond 200 calls.

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

5
int main() { clrscr(); int calls; float bill; cout<<"Enter number of calls : "; cin>>calls; if(calls<=100) bill=200; else if (calls>100 && calls<=150) { calls=calls-100; bill=200+(0.60*calls); } else if (calls>150 && calls<=200) { calls=calls-150; bill=200+(0.60*50)+(0.50*calls); } else { } cout<<" Your bill is Rs."<<bill; getch(); return 0; }
Any character is entered by the user; write a program to determine whether the character entered is a capital letter, a small case letter, a digit or a special symbol.The following table shows the range of ASCII values for various characters. Characters AZ az 09 special symbols ASCII Values 65 90 97 122 48 57 0 - 47, 58 - 64, 91 - 96, 123 127

calls=calls-200; bill=200+(0.60*50)+(0.50*50)+(0.40*calls);

#include<iostream.h> #include<conio.h> int main () { clrscr(); char ch; cout<<"Enter any character:"; cin>>ch; if (ch>=65 && ch<=90) cout<<"Character is a capital letter"; else if (ch>=97 && ch<=122) cout<<"Character is a small letter";

6
else if (ch>=48 && ch<=57) cout<<"Character is a digit"; else if ((ch>0 && ch<=47)||(ch>=58 && ch<=64)||(ch>=91 && ch<=96)||(ch>=123 && ch<=127)) cout<<"Character is a special symbol"; getch(); return 0; }

Vous aimerez peut-être aussi