Basic Programs

C++ program to implement Heap sort Algorithm

C++ program to implement Heap sort Algorithm

#include <iostream.h> const int MAX = 10 ; class array { private : int arr[MAX] ; int count ; public : array( ) ; void add ( int num ) ; void makeheap(int ) ; void heapsort( ) ; void display( ) ; } ; array :: array( ) { count = 0 ; for […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

C++ program to implement Quick sort Algorithm using class

C++ program to implement Quick sort Algorithm using class

#include <iostream.h> const int MAX = 10 ; class array { private :   int arr[MAX] ; int count ; public :   array( ) ; void add ( int item ) ; int getcount( ) ; static int split ( int *, int, int ) ; void quiksort ( int lower, int upper ) […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

C++ rogram to implement merge sort

C++ rogram to implement merge sort

#include <iostream.h> const int MAX = 5 ; class array { private : int *a ; int size ; int count ; public : array( ) ; array ( int sz ) ; void add ( int num ) ; void display( ) ; void merge_sort(int low,int high); void merge(int low,int mid,int high); ~array( ) […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

C++ program to implement Shell sort using class

C++ program to implement Shell sort using class

#include<iostream.h> #include<constream.h> void read(int a[10],int n) { cout<<"reading\n"; for(int i=0;i<n;i++) cin>>a[i]; } void display(int a[10],int n) { for(int i=0;i<n;i++) cout<<a[i]<<"\t"; } void shellsort(int a[10],int n) { int gap=n/2; do { int swap; do   { swap=0; for(int i=0;i<n-gap;i++) if(a[i]>a[i+gap]) { int t=a[i]; a[i]=a[i+gap]; a[i+gap]=t; swap=1; } } while(swap); } while(gap=gap/2); } void main() { int […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

C++ program to implement Insertion sort using class

C++ program to implement Insertion sort using class

#include <iostream.h> const int MAX = 10 ; class array { private : int arr[MAX] ; int count ; public : array( ) ; void add ( int item ) ; void sort( ) ; void display( ) ; } ; array :: array( ) { count = 0 ; for ( int i = […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

C++ program to implement Selection sort using class

C++ program to implement Selection sort using class

#include <iostream.h> const int MAX = 10 ; class array { private : int arr[MAX] ; int count ; public : array( ) ; void add ( int item ) ; void sort( ) ; void display( ) ; } ; array :: array( ) { count = 0 ; for ( int i = […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

C++ program to calculate the factorial of a number using recursion.

C++ program to calculate the factorial of a number using recursion.

Write a program to calculate the factorial of a number using recursion. #include<iostream.h> #include<conio.h> void main() { int n,fact; int rec(int); clrscr(); cout<<"Enter the number:->"; cin>>n; fact=rec(n); cout<<endl<<"Factorial Result are:: "<<fact<<endl; getch(); } rec(int x) { int f; if(x==1) return(x); else { f=x*rec(x-1); return(f); } }

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

C++ program to calculate a to the power b without using power function

C++ program to calculate a to the power b without using power function

Write a C++ program to calculate a to the power b without using power function. #include<iostream.h> #include<conio.h> void main() { int a,b,i,temp=1; clrscr(); cout<<"Enter number for operation"; cin>>a>>b; for(i=1;i<=b;i++) { temp=temp*a; } cout<<endl<<"Result are:: "<<temp; getch(); }

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

C++ program to multiply two numbers without using multiplication operator

C++ program to multiply two numbers without using multiplication operator

Write a c++ program to multiply two numbers without using multiplication operator. #include<iostream.h> #include<conio.h> void main () { int a,b,i,temp=0; clrscr(); cout<<"Enter Two numbers for multiplication"; cin>>a>>b; for(i=1;i<=b;i++) { temp=temp+a; } cout<<endl<<"Result are:: "<<temp; getch(); }

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

C++ programs for sorting a given numbers in ascending order using Merge sort

C++ programs for sorting a given numbers in ascending order using Merge sort

/* Write C++ programs for sorting a given list of elements in ascending order using Merge sort methods */ #include<iostream> #include<conio.h> using namespace std; void mergesort(int *,int,int); void merge(int *,int,int,int); int a[20],i,n,b[20];   main() { cout <<"\n enter no of elements"; cin >> n; cout <<"enter the elements"; for(i=0;i<n;i++) cin >> a[i]; mergesort(a,0,n-1); cout <<" […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone