Thursday, 23 March 2017

area calculator

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

void main()
{
clrscr();
float b,h,s,r,L,B;
int ch;

cout<<"\n\t ENTER The SHAPE \n\t[1] for triangle\n\t[2] for square\n\t[3] for circle \n\t[4] for rectangle\n\tPress choice  ";
cin>>ch;

switch(ch)
{
case 1: cout<<"\n ENTER BASE AND HEIGHT=";cin>>b>>h;
cout<<"\n AREA="<<0.5*b*h<<" sq.m"; break;
case 2: cout<<"\n ENTER SIDE=";cin>>s;
cout<<"\n AREA="<<s*s<<" sq.m";break;
case 3: cout<<"\n ENTER RADIUS=";cin>>r;
cout<<"\n AREA="<<3.14*r*r<<" sq.m";break;
case 4: cout<<"\n ENTER LENGTH AND BREADTH=";cin>>L>>B;
cout<<"\n AREA="<<L*B<<" sq.m";break;
default:cout<<"\n WRONG FUNCTIONS";

}

getch();
}

sum of series 1/1!-1/2!+1/3!-1/4!.....n

#include<iostream.h>
#include<conio.h>
int fact(int n)
{
if(n==1)
{
return 1;
}
else
{
return(n*fact(n-1));
}
}
void main()
{
clrscr();
int n,i; float sum=0;
cout<<"\n ENTER n ";
cin>>n;
for(i=1;i<=n;i++)
{
if(i%2==0)
{
sum=sum-fact(i);
}
else
{
sum=sum+fact(i);
}
}
cout<<"\n SUM= "<<sum;
getch();
}

sum of series 1/2!+1/3!+1/4!+....n

#include<iostream.h>
#include<conio.h>
int fact(int n)
{
if(n==1)
{
return 1;
}
else
{
return(n*fact(n-1));
}
}
void main()
{
clrscr();
int i,n;
float sum=0;
cout<<"\n ENTER n :  ";
cin>>n;
int x=2;
for(i=1;i<=n;i++)
{
sum=sum+(1)/(fact(x));
x++;
}
cout<<"\n SUM= "<<sum;
getch();
}

Wednesday, 1 February 2017

series program

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

int sum(int);

void main()
{

clrscr();

int i,n,r;

cout<<"\n ENTER n ";
cin>>n;

for(i=1;i<=n;i++)
{
     if(i==n)
       {
             cout<<i<<"^2"<<"=";
        }
     else
      {
            cout<<i<<"^2"<<"+";
       }
 }
r=sum(n);

cout<<sum;

getch();

}

int sum(int n)
{

int i,sum=0;

for(i=1;i<=n;i++)
{
    sum+=(i*i);
}

return(sum);

}



OUTPUT:

1^2+2^2+3^2+.....+n^2.

DIGITAL CLOCK

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#define SIZE 40

void display(int def_x, int def_y, int k)
{
int arrlight[10][20]={ 0,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,1,
0,1,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,1,1,1,
0,1,1,1,0,0,0,1,0,1,1,1,0,1,0,0,0,1,1,1,
0,1,1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,1,
0,1,0,1,0,1,0,1,0,1,1,1,0,0,0,1,0,0,0,1,
0,1,1,1,0,1,0,0,0,1,1,1,0,0,0,1,0,1,1,1,
0,1,1,1,0,1,0,0,0,1,1,1,0,1,0,1,0,1,1,1,
0,1,1,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,
0,1,1,1,0,1,0,1,0,1,1,1,0,1,0,1,0,1,1,1,
0,1,1,1,0,1,0,1,0,1,1,1,0,0,0,1,0,1,1,1};
int arrx1[SIZE],arrx2[SIZE],arry1[SIZE],arry2[SIZE];
int x=0,y=0,i=0,j=0,pos=0,l=0;
x=def_x; y=def_y;
for(i=0;i<5;i++)
{
for(j=0;j<4;j++)
{
arrx1[pos]=x; arry1[pos]=y;
arrx2[pos]=x+10; arry2[pos]=y+10;
pos++;
x=x+15;
}
x=def_x;
y=y+15;
}

for(l=0;l<20;l++)
{
setfillstyle(1,BLACK);
bar(arrx1[l],arry1[l],arrx2[l],arry2[l]);
}
for(l=0;l<20;l++)
{

if(arrlight[k][l]==1)
{ setfillstyle(1,GREEN); }
else
{ setfillstyle(1,BLACK);}
bar(arrx1[l],arry1[l],arrx2[l],arry2[l]);
}
}

void main()
{
clrscr();
int hr,min;
cout<<"\n Enter Hours to set alaram (0 - 23) :"; cin>>hr;
cout<<"\n Enter Minute to set alaram (0 - 59) :"; cin>>min;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
struct time t;
int mdgt,mudgt,mtdgt,hdgt,hudgt,htdgt,sdgt,sudgt,stdgt;
while(!kbhit())
{
gettime(&t);
sdgt=t.ti_sec; stdgt=t.ti_sec/10; sudgt=sdgt-(stdgt*10);
mdgt=t.ti_min; mtdgt=t.ti_min/10; mudgt=mdgt-(mtdgt*10);
hdgt=t.ti_hour; htdgt=t.ti_hour/10; hudgt=hdgt-(htdgt*10);
if((sdgt%2)==0)
{
display(100,200,htdgt); display(180,200,hudgt);
setfillstyle(1,BLACK);
bar(245,200,255,225);bar(245,250,255,275);
display(260,200,mtdgt); display(340,200,mudgt);
setfillstyle(1,BLACK);
bar(405,200,415,225);bar(405,250,415,275);
display(420,200,stdgt); display(500,200,sudgt);
}
else
{
display(100,200,htdgt); display(180,200,hudgt);
setfillstyle(1,GREEN);
bar(245,200,255,225);bar(245,250,255,275);
display(260,200,mtdgt); display(340,200,mudgt);
setfillstyle(1,GREEN);
bar(405,200,415,225);bar(405,250,415,275);
display(420,200,stdgt); display(500,200,sudgt);
}
if(t.ti_min==min && t.ti_hour==hr)
{
sound(300);
delay(500);
nosound();
}
delay(1000);
}
closegraph();
restorecrtmode();
cout<<"\nPress Any Key to exit!";
getch();
}

TRIANGLE with alphabets

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

void main()

{

clrscr();

int i,n,j;
char ch;

cout<<"\n ENTER NUMBER OF ROWS ";
cin>>n;
cout<<"\n ";

for(i=1 ; i<=n ; i++)
{
ch='A';
for(j=1 ; j<=i ; j++)
{
cout<<ch;
ch++;
}
cout<<"\n";
}

getch();

}


OUTPUT :

A
AB
ABC
ABCD
ABCDE



Sunday, 22 January 2017

complex nos.' functions calculator

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

struct complex
{
float r1;
float r2;
}a,b;

void sum(complex &a,complex &b);
void sub(complex &a,complex &b);
void mul(complex &a,complex &b);
void div(complex &a,complex &b);

void main()
{
clrscr();
complex a,b;
int ch;
cout<<"\n ENTER a AND b of a+ib : ";
cin>>a.r1>>a.r2;
cout<<"\n ENTER c AND d of c+id : ";
cin>>b.r1>>b.r2;

cout<<"\n SELECT OPTION : ";
cout<<"\n (1) ADDITION ";
cout<<"\n (2) SUBTRACTION ";
cout<<"\n (3) MULTIPLICATION ";
cout<<"\n (4) DIVISION ";
cin>>ch;

switch(ch)
{
case 1 : sum(a,b);break;
case 2 : sub(a,b);break;
case 3 : mul(a,b);break;
case 4 : div(a,b);break;
default : cout<<"\n WRONG OPTION ";break;
}

getch();

}

void sum(complex &a,complex &b)
{
cout<<"\n RESULT = ("<<(a.r1+b.r1)<<")+("<<(b.r2+a.r2)<<")i";
}
void mul(complex &a,complex &b)
{
cout<<"\n RESULT = ("<<((a.r1*b.r1)-(a.r2*b.r2))<<")+("<<((a.r1*b.r2)+(a.r2*b.r1))<<")i";
}
void sub(complex &a,complex &b)
{
cout<<"\n RESULT = ("<<(a.r1-b.r1)<<")+("<<(a.r2-b.r2)<<")i";
}
void div(complex &a,complex &b)
{
cout<<"\n RESULT = ("<<((a.r1*b.r1)+(a.r2*b.r2))/((b.r1*b.r1)+(b.r2*b.r2))<<")+("<<((b.r1*a.r2)-(a.r1*b.r2))/((b.r1*b.r1)+(b.r2*b.r2))<<")i";
}


OUTPUT :