Bigger

Friday, 14 November 2014

How to change text color in dos box /Turbo c++ compiler

---------------------------------------------------------------------
#include<conio.h>
int main()
{
int i;

 for (i=1;i<=10;i++)
{
textcolor(i);
cprintf("  %d  ",i);
}
getch();
return 0;
}
//textcolor is a function defined in conio.h library
--------------------------------------------------------------------------
output:-

Tuesday, 11 November 2014

How to use Sound function in c programming

#include<iostream.h>
#include<conio.h>
#include<dos.h>
void main()
{
int i;
clrscr();
for(i=150;i<=250;i++)
{
sound(i);
delay(100);
}
for(i=250;i>=250;i--)
{
sound(i);
delay(100);
}
nosound();
getch();
}

Sunday, 9 November 2014

Tower of Hanoi in C

------------------------------------------------------------------------------
#include<iostream>
#include<stdlib.h>
using namespace std;
void towers(int n,char source,char inter,char destination);
int main()
{
int n;
cout<<"\nEnter the number of disks";
cin>>n;
towers(n,'A','B','C');
return 0;
}

void towers(int n,char source,char inter,char destination)
{
//Moving 1 disk from A to C
if(n==1)
{
cout<<"\nMove disk 1 from A to C";
return ;
}
// move n-1 disks from A to B using C
towers(n-1,source,destination,inter);
cout<<"\nMove disk "<<n<<" from "<<source<<" to "<<destination;
//move n-1 disks from B to C USing A
towers(n-1,inter,source,destination);
}//end of the tower function

----------------------------------------------------------------
output:-



How to make a twinkling bulb in HTML/JScript

Learning Point :- This program basically tells that how we can change the
HTML data using JavaScript.....
------------------------------------------------------------------------------------
<html>
<head>
</head>
<body>
<img  id="myimage" src="off.jpg" height="150" width="100" onclick="myFunction()">
<script>
var myVar=setInterval(function(){myFunction()},300);
function myFunction()
{
var image=document.getElementById('myimage');
if(image.src.match("off.jpg"))
{
image.src="on.jpg";
}
else
{
image.src="off.jpg";
}
}
</script>
</body>
</html>

---------------------------------------------------------------------------------------
output:-
This will result in a bulb which is continuously switching on and off in every 300 ms(or 0.3 sec)
---------------------------------------------------------------------------------------------
Note:-You  should download 2 images of a bulb from google
1.)Image for off state (saved it with name off.png/jpg)
2.)Image for on state (saved it with name on.png/jpg)
---------------------------------------------------------------------------------------

Saturday, 8 November 2014

Christmas tree in C programming

--------------------------------------Christmas  tree in C Programming----------------------------------
#include<iostream>
using namespace std;

int  main()
{
for(int i=0;i<=2;i++)
{
for(int j=1;j<=3;j++)
{
for(int sp=5-j-i;sp>0;sp--)
{
cout<<" ";
}
for(int k=1;k<=(2*j+2*i-1);k++)
{
cout<<"*";
}
cout<<endl;
}
}
for(int l=1;l<=3;l++)
{
for(int m=1;m<=3;m++)
{
cout<<" ";
}
for(int n=1;n<=3;n++)
{
cout<<"*";
}
cout<<"\n";
}
}//brackets of main
------------------------------------------------------------------------------------------------------------
output:-








Bouncing Ball screensaver in C

Just Run it to see the magic....
-------------------------------------------------------------------------------------------------------------
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
int main()
{
clrscr();
randomize();
float ballx=rand()%76+2,bally=rand()%20+2;
float velx=1,vely=1;
int i=0;
while(!kbhit())
{
i++;
textcolor(i);
delay(100);
clrscr();
if(1)
{
if(ballx<2)
velx=-velx;
else if(ballx>78)
velx=-velx;
}
if(1)
{
if(bally<=1)
vely=-vely;
else if(bally>=23)
vely=-vely;

}
ballx+=velx;
bally+=vely;
gotoxy(ballx,bally);
cprintf("*");
}
getch();
return 0;
}

------------------------------------------------------------------------------------------------
Note:-This program will exclusively run in dosbox.... 

output:-
Moving the ball and get reflected back on striking the end of screen

If you want the video clip of it's output then just put a mail to me....


How to make screensaver in c programming

Just Run it to see the magic....
-------------------------------------------------------------------------------------------------------------
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
int main()
{
clrscr();
randomize();
float ballx=rand()%76+2,bally=rand()%20+2;
float velx=1,vely=1;
int i=0;
while(!kbhit())
{
i++;
textcolor(i);
delay(100);
clrscr();
if(1)
{
if(ballx<2)
velx=-velx;
else if(ballx>78)
velx=-velx;
}
if(1)
{
if(bally<=1)
vely=-vely;
else if(bally>=23)
vely=-vely;

}
ballx+=velx;
bally+=vely;
gotoxy(ballx,bally);
cprintf("SofTecH");
}
getch();
return 0;
}

------------------------------------------------------------------------------------------------
Note:-This program will exclusively run in dosbox.... 

output:-
Moving and name and get reflected back on striking the end of screen

If you want the video clip of it's output then just put a mail to me....