Binary Search in C++

Here you will learn about binary search in C++. Binary search is an algorithm used to search for an element in a sorted array. In this algorithm the targeted element is compared with middle element. If both elements are equal then position of middle element is returned and hence targeted element is found. If both …

Binary Search in C++ Read More »

C++ Program To Print ASCII value of Digits,Uppercase and Lowercase Alphabates

#include<conio.h>#include<iostream.h>#include<dos.h>#include<process.h> void main(){ clrscr(); char ch,a[]={“Made By : Neeraj Mishra”}; int j=0; cout<<“Uppercase Alphabatesnn”; for(int i=65;i<91;++i) { j++; ch=i; cout<<ch<<“:”<<i<<“t”; if(j==10) { cout<<“n”; j=0; } } j=0; cout<<“nnnLowercase Alphabatesnn”; for(i=97;i<123;++i) { j++; ch=i; cout<<ch<<“:”<<i<<“t”; if(j==10) { cout<<“n”; j=0; } } cout<<“nnnDigitsnn”; for(i=48;i<58;i++) { ch=i; cout<<ch<<“:”<<i<<“t”; } cout<<“nnnntt”; for(i=0;a[i]!=’’;++i) { cout<<a[i]; sleep(1); } exit(0);}

C++ Program to read from a text file and than write in another text file

#include<fstream.h> void main(){ ofstream fout(“sare1.txt”); //create a file to writeifstream fin(“sare1.txt”);fout<<“Hello….!!”;fout.close();                            //closing the file fout.open(“sare2.txt”); //create file to writechar ch;while(fin) //loop wiill run till end of file{fin>>ch;       //reading data from filefout<<ch;       //writing data to file}fin.close();fout.close();}/*you can …

C++ Program to read from a text file and than write in another text file Read More »

Tic-Tac-Toe Game

#include<iostream.h> #include<conio.h> #include<dos.h> #include<process.h> char mat[3][3]; void table(void);            //function to print the table void welcome(void);     //function for welcome screen void main() {  welcome();      A: clrscr();  int i,j,m,n,sum=0;  char ch;  for(m=0;m<3;++m)   for(n=0;n<3;++n)    mat[m][n]=’’;  table();  while(sum<10)  {  //for player 1  cout<<“Player 1 is’x’nChoose the position:”;  cout<<“nRow:”; …

Tic-Tac-Toe Game Read More »

C++ Program to print a man using graphics

#include<graphics.h> #include<iostream.h> #include<stdlib.h> #include<stdio.h> #include<conio.h> void main() {    int gdriver=DETECT,gmode;    initgraph(&gdriver, &gmode, “c:\turboc3\bgi”);    //for head    ellipse(320,95,360,0,25,20);    line(298,85,341,85);    circle(310,90,2);    circle(330,90,2);    arc(320,100,200,-20,10);    //for neck    line(313,115,313,125);    line(328,115,328,125);    //For centre part    arc(320,225,72,107,100);    line(290,129,290,200);    line(350,129,350,200);    line(290,193,350,193);    line(290,200,350,200);    //for legs    line(290,200,285,280);   …

C++ Program to print a man using graphics Read More »

C++ Program to convert a lowercase alphabet to uppercase or vice-versa

#include<iostream.h> #include<conio.h> void main() { clrscr(); char ch; cout<<“Enter any Alphabet:”; cin>>ch; if(ch>=’a’&&ch<=’z’) { cout<<“ntYou have entered a lowercase alphabet”; ch=ch-32; cout<<“nnThe uppercase alphabet is “<<ch; } else { cout<<“ntYou have entered an Uppercase alphabet”; ch=ch+32; cout<<“nnThe lowercase alphabet is “<<ch; } getch(); }

C++ Program to print three numbers in descending order

#include<iostream.h>#include<conio.h> void main(){ clrscr(); int a,b,c,big1,big2,big3; cout<<“Enter three numbers:”; cin>>a>>b>>c;  big1=a; if(b>big1) big1=b; else if(c>big1) big1=c; if(big1==a) { if(b>c) { big2=b; big3=c; } else { big2=c; big3=b; } } else { if(big1==b) if(a>c) { big2=a; big3=c; } else { big2=c; big3=a; } else { if(a>b) { big2=a; big3=b; } else { big2=b; big3=a; } } …

C++ Program to print three numbers in descending order Read More »