"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain
Showing posts with label Startup Simple Programs. Show all posts
Showing posts with label Startup Simple Programs. Show all posts

Tuesday, April 27, 2010

WAP to input acceleration (cm/sec*sec) and time . calculate the final velocity of an object , that is initially static.

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



void main()
{
int ac, t, v;


cout<< "Enter acceleration in cm per second square ";
cin >> ac;
cout<< " Enter time to travarse ";
cin >> t;


v = ac * t; 
// formula of final vel = initial vel + acceleration * time (initial vel = 0)


cout << " Final velocity = " << v << " cm / sec*sec ";


getch();
}

WAP to convert given inches into its equivalent yards , feet, inches. (1 yard = 36 inches, 1 foot = 12 inches)

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

void main()
{
int in, yrd, ft, r;


cout<< " Enter distance/length in inches ";
cin>> in;


yrd = in/ 36; // calculate yard
r = in % 36; // remaining inches 
ft = r / 12; // calculate feet
r = r % 12; // remaining inches


cout<< " \n The distance in inches is " << in ;
cout << " \n The equivalent yard-feet-inches = " << yrd << " yard" << ft << "feet" << r << "inches" ;
getch();
}

Monday, April 26, 2010

WAP to input a 3 digit number. Print the digits of unit place, tenths place and hundredths place

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

#include<process.h>


void main()
{
int n, u, t, h, r;


cout<<" Enter a number (with 3 digits) ";
cin>> n;


if( n < 100 || n > 999)
{
cout<< "\n It is not a 3 digit no. ! Abort  ";
getch();
exit(1);
}


u = n % 10; // digit of unit place 
r = n / 10; // remaining two digits
t = r % 10; // digit of tenths place
h = r / 10; // digit of hundredths place


cout<< "\n unit place Digit = " << u;
cout<< "\n ten's place Digit = " << t;
cout << "\n Hundredths place Digit = " << h;


getch();
}

Write a program to calculate simple interest and compound interest

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

#include<math.h>


void main()
{
double p, r, t, i, am;


cout<< " Enter principal, rate , time ?";
cin>> p >> r >> t;


// Calculate Simple interest
i = (p * r* t) / 100;
am = p + i;


cout<< "\n Principal Amt = Rs. " << p;
cout<< "\n Rate = " << r << "%" ;
cout << "\n Time = " << t << "yrs.";
cout<< "\n The Interest Amt = Rs. " << i ;
cout<< "\n The Total Amt = Rs. " << am;


// Calculate Compound interest
am = pow((p* ( 1 + (r/100)), t);
i = am - p;


cout << "\n The Interest Amt = Rs. " << i;
cout<< "\n The Total Amt = Rs. " << am;


getch();
}

WAP to calculate the size of integer, character, float , double datatype


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


void main()
{
clrscr();
cout<< " \nSize of character = " << sizeof(char);
cout<< " \nSize of integer = " << sizeof(int);
cout<< "\n Size of float = " << sizeof(float);
cout<< "\n Size of double = " << sizeof(double);
getch();
}


ALTERNATIVELY,

#include(iostream.h)
#include(conio.h)

void main()
{
clrscr(); 
int n;
float f;
char c;
double d;
cout<< " \nSize of character= " << sizeof(c);
cout<< " \nSize of integer = " << sizeof(n);
cout<< "\n Size of float = " << sizeof(f);
cout<< "\n Size of double = " << sizeof(d);
getch();
}


WAP to input your height in feet and inches. Convert it into centimeter.


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

void main()
{
clrscr();
int in, feet, cm;
cout<< "\n Enter your height in feet and inches respectively :";
cout<<"\nYour height is " << feet <<"ft" << in << "inches";
cin >> feet >> in;
in = in + feet * 12;
 cm = in * 2.54;
cout << "\n Your height in  cm. is " <<  cm;
getch();
}

WAP to input time in seconds and convert it into hh-mm-ss format


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

void main()
{
int sec, s, m, h;

cout<< "\n Enter time in seconds :";
cin >> sec;
h = sec/3600; //hours
sec = sec%3600; // remaining seconds
m = sec/60; // minutes
s = sec%60; // remaining seconds

cout << "\n HH-MM-SS  : " << h << ":" << m << ":" << s;
getch();
}

WAP to input dividend and divisor. Calculate quotient and remainder.


#include<iostream.h>
#include<conio.h>
void main()
{
int div, dis, q , r;

cout<< "Enter dividend & divisor :";
cin >> div >> dis;

q = div / dis;
r  = div % dis;

cout << " Quotient = " << q;
cout << "Remainder = " << r;

getch();
}

Write a program to input 3 sides of a triangle and calculate its area.



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

void main()
{
double s1, s2, s3, ar, s;

cout<< "Enter 3 sides :";
cin >> s1 >> s2 >> s3;
s = (s1+s2+s3)/2;
ar = sqrt( s * ( s - s1) * (s  - s2) * (s - s3));
cout << "\n The Area of the triangle = " << ar;
getch();
}
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.