Neeraj Mishra

A crazy computer and programming lover. He spend most of his time in programming, blogging and helping other programming geeks.

C++ Program to print following triangle:

         *       *  *      *    *     ***** code: #include<iostream.h>#include<conio.h> void main(){ clrscr(); int i,k,j,n; cout<<“Enter size of triangle in odd number(min-5,ex-5,7,9):”; cin>>n; cout<<“nt”; for(i=1;i<=n;i+=2) { for(j=n;j>i;j-=2) cout<<” “; for(k=1;k<=i;++k) { if(i==n) cout<<“*”; else if(k==1||k==i) cout<<“*”; else cout<<” “; } cout<<“nt”; } getch();}

C++ Program to print following triangle:

      *     **   *** ****code: #include<iostream.h>#include<conio.h> void main(){ clrscr(); int i,n,j,k; cout<<“Enter size of triangle(ex-5):”; cin>>n; cout<<“nt”; for(i=0;i<n;++i) { for(j=n;j>i;–j) cout<<” “; for(k=0;k<+i;++k) cout<<“*”; cout<<“nt”; } getch();}

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 »