Neeraj Mishra

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

Linear Search in C++

Here you will get program for linear search in C++. In linear search algorithm, we compare targeted element with each element of the array. If the element is found then its position is displayed. The worst case time complexity for linear search is O(n). Program for Linear Search in C++ #include<iostream> using namespace std; int main() …

Linear Search in C++ Read More »

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();}

C++ Program to print following triangle:

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