1
|
Write a program which input principal, rate and time from user and calculate compound interest. You can use library function. CI = P(1+R/100) T - P
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
float P,R,T,CI;
cout<<"Enter Principal, Rate and Time : ";
cin>>P>>R>>T;
CI=P*pow((1+R/100),T) - P;
cout<<"Compound Interest is : "<<CI;
getch();
return 0;
}
|
2
|
Write a program to compute area of triangle. Sides are input by user. Area = sqrt(s*(s-a)*(s-b)*(s-c)) where s=(a+b+c)/2.
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
float a,b,c,s,Area;
cout<<"Enter three sides of triangle : ";
cin>>a>>b>>c;
s=(a+b+c)/2;
Area=sqrt(s*(s-a)*(s-b)*(s-c));
cout<<"Area of triangle is : "<<Area;
getch();
return 0;
}
|
3
|
Write a program to check character entered is alphabet, digit or special character using library functions.
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<stdio.h>
int main()
{
char ch;
cout<<"Enter any character :";
ch=getchar();
if(isalpha(ch))
cout<<"Alphabet";
else if(isdigit(ch))
cout<<"Number";
else
cout<<"Special Character";
getch();
return 0;
}
|
4
|
Write a program which display a number between 10 to 100 randomly.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
int n;
randomize();
n=random(91)+10;
cout<<"The randomly selected number is :"<<n;
getch();
return 0;
}
|
5
|
Write a program which accept a letter and display it in uppercase letter.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<ctype.h>
int main()
{
char ch;
cout<<"Enter any character :";
ch=getchar();
ch=toupper(ch);
cout<<ch;
getch();
return 0;
}
|
6
|
Write a C++ program to implement the Number Guessing Game. In this game the computer chooses a random number between 1 and 100, and the player tries to guess the number in as few attempts as possible. Each time the player enters a guess, the computer tells him whether the guess is too high, too low, or right. Once the player guesses the number, the game is over.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int num, guess, tries = 0;
srand(time(0)); num = rand() % 100 + 1; cout << "Guess My Number Game\n\n";
do
{
cout << "Enter a guess between 1 and 100 : ";
cin >> guess;
tries++;
if (guess > num)
cout << "Too high!\n\n";
else if (guess < num)
cout << "Too low!\n\n";
else
cout << "\nCorrect! You got it in " << tries << " guesses!\n";
} while (guess != num);
cin.ignore();
cin.get();
return 0;
}
|
No comments:
Post a Comment