/*
4 3 2 1
0 3 2 1
0 0 2 1
0 0 0 1
*/
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,g,j,a[100],b[100][100];
cout<<"Enter Limit"<<endl;
cin>>n;
cout<<"Enter "<<endl;
for(g=0;g<n;g++)
cin>>a[g];
for(i=0;i<n;i++)
{
for(j=n-1;j>=0;j--)
{
b[i][j]=a[j];
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i>j)
b[i][j]=0;
}
}
for(i=0;i<n;i++)
{
cout<<endl;
for(j=0;j<n;j++)
{
cout<<b[i][j]<<" ";
}
}
getch();
}
Programs Can Also Be Downloaded From The Folders Below....[Or Scroll Down]
Showing posts with label Class XII. Show all posts
Showing posts with label Class XII. Show all posts
Array in given pattern
Click Here To Download C++ File Of This Program
Predict Output 2
Click Here To Download C++ File Of This Program
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
void main()
{
clrscr();
char *Name="AnnUal ExaMiNaTION";
for(int x=0;x<strlen(Name);x++)
if(islower(Name[x]))
Name[x]=toupper(Name[x]);
else
if(isupper(Name[x]))
if(x%2!=0)
Name[x]=tolower(Name[x-1]);
else
Name[x]--;
cout<<Name<<endl;
getch();
}
Predict Output
Click Here To Download C++ File Of This Program
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int i=0,ua=0,ub=0,uc=0,fail=0;
while(i<=5)
{switch(i++)
{case 1:
case 2:++ua;
case 3:
case 4:++ub;
case 5:++uc;
default:++fail;
}
}
cout<<" ua="<<ua<<",ub="<<ub<<",uc="<<uc<<",fail="<<fail;
getch();
}
Pascals Triangle & Pattern
Click Here To Download C++ File Of This Program
//prg to display diamond and pascals triangle
//Downloaded From www.c4cpp.co.nr. (C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x,i,f,r,b,g,c,h,v=1,q,j,n,p,k=1;
int ch;
cout<<"Enter choice 1:STARS"<<endl;
cout<<" 2:NUMBERS"<<endl;
cin>>ch;
switch(ch)
{
//WITH STAR
case 1:
v=2;
char a2[100][100];
cout<<"Enter Limit : "<<endl;
cin>>n;
p=n-1;
//INPUTTING
for(i=0;i<=(2*n)-2;i++)
{
for(j=0;j<=(2*n)-2;j++)
{
a2[i][j]= ' ';
}
}
//STARTING
for(i=0;i<=(2*n)-2;i++)
{
for(j=0;j<=(2*n)-2;j++)
{
if(((i+j)==p)&&(i<n))
{
for(c=0;c<k;c++)
{
a2[i][j]='*';
j=j+v;
}
k++;
j=(2*n)-2;
r=c-1;
}
if(((i+j)==(p+2))&&(i>=n))
{
for(h=r;h>0;h--)
{
a2[i][j]='*';
j=j+v;
}
p=p+2;
r--;
j=(2*n)-2;
}
}
}
for(i=0;i<=(2*n)-2;i++)
{
cout<<endl;
for(j=0;j<=(2*n)-2;j++)
{
cout<<a2[i][j];
}
}
break;
//CASE TWO WITH NUMBERS
case 2:
int a[100][100];
cout<<"Enter Limit : "<<endl;
cin>>n;
p=n-1;
for(i=0;i<=(2*n)-2;i++)
{
for(j=0;j<=(2*n)-2;j++)
{
a[i][j]=0;
}
}
for(i=0;i<=(2*n)-2;i++)
{
for(j=0;j<=(2*n)-2;j++)
{
if(((i+j)==p)&&(i<n))
{
b=1;
for(c=0;c<k;c++)
{
if(j<=(n-1))
{
a[i][j]=b;
j=j+v;
b++;
r=b-2;
}
if(j>(n-1))
{
a[i][j]=r;
j=j+v;
r--;
}
}
k=k+2;
j=(2*n)-2;
r=c-2;
}
if(((i+j)==p+2)&&(i>=n))
{
f=1;
for(h=r;h>0;h--)
{
if(j<=(n-1))
{
a[i][j]=f;
j=j+v;
f++;
x=f-2;
}
if(j>(n-1))
{
a[i][j]=x;
j=j+v;
x--;
}
}
r=r-2;
p=p+2;
j=(2*n)-2;
}
}
}
for(i=0;i<=(2*n)-2;i++)
{
cout<<endl;
for(j=0;j<=(2*n)-2;j++)
{
if(a[i][j]!=0)
cout<<a[i][j];
else
cout<<" ";
}
}
break;
default:
cout<<"Wrong choice"<<endl;
break;
}
getch();
}
Decimal To Binary & vice versa
Click Here To Download C++ File Of This Program
//prg to conv decimal to binary & binary to decimal
//Downloaded From www.c4cpp.co.nr. (C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int a,g,h,s=0,i=0,d,b,ch;
cout<<endl<<"Enter the choice - "<<endl<<"1:Binary to Decimal"<<endl<<"2:Decimal to Binary"<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter the Binary Digit"<<endl;
cin>>b;
while(b>0)
{
a=b%10;
s=s+a*(pow(2,i));
i=i+1;
b=b/10;
}
cout<<"Answer ="<<s<<endl;
break;
case 2:
cout<<"Enter the Decimal"<<endl;
cin>>d;
while(d>0)
{
a=d%2;
a=a*pow(10,i);
s=s+a;
i=i+1;
d=d/2;
}
cout<<"Answer ="<<s<<endl;
break;
default:
cout<<"Wrong choice"<<endl;
break;
}
getch();
}
Travel Plan ( Classes )
Click Here To Download C++ File Of This Program
//PROGRAM
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
//class
class travelplan
{long plancode;
char place[10];
int noofpeople;
int noofbus;
public:
travelplan();
void newplan();
void showplan();
}travel;
void travelplan::travelplan()
{cout<<"enter the plancode"<<endl;
cin>>plancode;
cout<<endl;
cout<<"enter the place"<<endl;
gets(place);
cout<<endl;
cout<<"enter the no of travellers"<<endl;
cin>>noofpeople;
cout<<endl;
}
void travelplan::newplan()
{if(noofpeople<20)
{noofbus=1;}
else if((noofpeople>=20)&&(noofpeople<40))
{noofbus=2;}
else if(noofpeople>=40)
{noofbus=3;}
}
void travelplan::showplan()
{cout<<"Plan code : "<<plancode<<endl;
cout<<"Place : ";
puts(place);
cout<<endl;
cout<<"No of travellers : "<<noofpeople<<endl;
cout<<"No of bus : "<<noofbus<<endl;
}
void main()
{travel.newplan();
travel.showplan();
getch();
}
Area of Triangle ( Function Overloading )
Click Here To Download C++ File Of This Program
//PROGRAM (c)c4cpp.co.nr
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<math.h>
//function 1
void area(float r)
{float area_c;
area_c=(3.14*r*r);
cout<<"Area of the circle="<<area_c<<endl;
}
//function 2
void area(int l,int h)
{float area_r;
area_r=l*h;
cout<<"Area of the rectangle = "<<area_r<<endl;
}
//function 3
void area(float a,float b,float c)
{float s,area_t ;
s=(a+b+c)/2;
area_t=pow((s*(s-a)*(s-b)*(s-c)),0.5);
cout<<"Area of the triangle = "<<area_t<<endl;
}
void main()
{
clrscr();
int ch;
float r,a,b,c,l,h;
cout<<"1.Area of circle"<<endl<<"2.Area of rectangle"<<endl;cout<<"3.Area of triangle"<<endl<<"4.Exit"<<endl;
X:
cout<<"Enter the choice"<<endl;
cin>>ch;
switch(ch)
{
case 1:cout<<"Enter the radius of the circle"<<endl;
cin>>r;
void area (float);
area(r);
goto X;
case 2:cout<<"Enter the sides of rectangle"<<endl;
cin>>l>>h;
void area (float,float);
area (l,h);
goto X;
case 3:cout<<"Enter the sides of triangle"<<endl;
cin>>a>>b>>c;
void area (float,float,float);
area (a,b,c);
goto X;
case 4:exit(0);
default:cout<<"Wrong Choice"<<endl;
goto X;}
getch();}
Circular Queue
Click Here To Download C++ File Of This Program
//Circular queue
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
#include<process.h>
class queue
{int data[10];
int front,rear;
public:
queue()
{front=-1;
rear=-1;
}
void add();
void remove();
void display();
};
void queue::add()
{if((rear+1==front)||(rear==9&&front==0))
{cout<<"Overflow ";
}
else
{if((rear==-1) &&(front==-1))
{rear=0;
front=0;
}
else if(rear==9)
{rear=0;
}
else
{rear++;
}
cout<<"Enter the element ";
cin>>data[rear];
}
}
void queue::remove()
{if(front==-1&&rear==-1)
{cout<<"Underflow ";
}
else
{if(front==9)
{front=0;
}
else if(front==rear)
{front=-1;
rear=-1;
}
else
{front++;
}
}
}
void queue::display()
{int i=0,n=9;
if(rear==-1)
{cout<<"No elements.."<<endl;
}
else
{ if(rear>front)
{for(i=0;i<front;i++)
{cout<<"_";
}
for(i=front;i<=rear;i++)
{cout<<data[i];
}
for(i=rear+1;i<n;i++)
{cout<<"_";
}
}
else
{for(i=0;i<=rear;i++)
{cout<<data[i];
}
for(i=rear+1;i<front;i++)
{cout<<"_";
}
for(i=front;i<n;i++)
{cout<<data[i];
}
} }
}
void main()
{clrscr();
int ch;
queue queue;
X:
cout<<"\nEnter your choice\n1.Insert\n2.Delete\n3.Display\n4.Exit\n";
cin>>ch;
switch(ch)
{case 1:queue.add();
goto X;
case 2:queue.remove();
goto X;
case 3:queue.display();
goto X;
case 4:exit(0);
}
getch();
}
Queue As Linked List
Click Here To Download C++ File Of This Program
//Queue as a linked list
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<stdio.h>
#include<string.h>
struct node
{char name[20];
int age;
node *link;
}*ptr=NULL,*save=NULL;
class queue
{node *rear,*front;
public:
queue()
{rear=NULL;
front=NULL;
}
void queins();
void quedel();
void display();
}q;
void queue::queins()
{ptr=new node;
if(ptr==NULL)
{cout<<"Queue overflow ";
}
else
{cout<<"Enter the name ";
gets(ptr->name);
cout<<"Enter the age ";
cin>>ptr->age;
ptr->link=NULL;
if(rear==NULL)
{rear=ptr;
front=ptr;
}
else
{rear->link=ptr;
rear=ptr;
}
}
}
void queue::quedel()
{if(rear==NULL)
{cout<<"Queue underflow ";
}
else
{if(front==rear)
{save=front;
front=NULL;
rear=NULL;
cout<<"Name ";
puts(save->name);
cout<<"Age "<<save->age;
delete save;
}
else
{save=front;
front=front->link;
cout<<"Name ";
puts(save->name);
cout<<"Age "<<save->age;
delete save;
}
}
}
void queue::display()
{if(rear==NULL)
{cout<<"No elements ";
}
else
{ptr=front;
while(ptr!=NULL)
{cout<<"Name ";
puts(ptr->name);
cout<<"Age "<<ptr->age;
ptr=ptr->link;
}
}
}
void main()
{clrscr();
int ch;
X:
cout<<"\nEnter your choice\n1.Insert\n2.Delete\n3.Display\n4.Exit\n";
cin>>ch;
switch(ch)
{case 1:q.queins();
goto X;
case 2:q.quedel();
goto X;
case 3:q.display();
goto X;
case 4:exit(0);
default:cout<<"Wrong choice ";
goto X;
}
getch();
}
Stack as Linked List
Click Here To Download C++ File Of This Program
//Stack as a linked list
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<stdio.h>
struct node
{char name[20];
int age;
node *link;
}*ptr=NULL,*save=NULL;
class stack
{node *top;
public:
stack()
{top=NULL;
}
void stackpush();
void stackpop();
void display();
}st;
void stack::stackpush()
{ptr=new node;
if(ptr==NULL)
{cout<<"Overflow ";
}
else
{cout<<"Enter the name ";
gets(ptr->name);
cout<<"Enter the age ";
cin>>ptr->age;
ptr->link=NULL;
if(top==NULL)
{top=ptr;
}
else
{ptr->link=top;
top=ptr;
}
}
}
void stack::stackpop()
{if(top==NULL)
{cout<<"Underflow ";
}
else
{save=top;
top=top->link;
cout<<"Name ";
puts(save->name);
cout<<"Age "<<save->age;
delete save;
}
}
void stack::display()
{if(top==NULL)
{cout<<"No elements.."<<endl;
}
else
{ptr=top;
while(ptr!=NULL)
{cout<<"\nName ";
puts(ptr->name);
cout<<"Age "<<ptr->age;
ptr=ptr->link;
}
}
}
void main()
{clrscr();
int ch;
X:
cout<<"\nEnter your choice\n1.Insert\n2.Delete\n3.Display\n4.Exit\n";
cin>>ch;
switch(ch)
{case 1:st.stackpush();
goto X;
case 2:st.stackpop();
goto X;
case 3:st.display();
goto X;
default:cout<<"Wrong choice ";
goto X;
case 4:exit(0);
}
getch();
}
Progress Report
Click Here To Download C++ File Of This Program
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<stdio.h>
#include<fstream.h>
struct stud
{
public:
int rno;
char name[50];
int cls;
float marks[5];
};
struct res
{
int rnos;
float total;
char grade;
float perc;
};
void main()
{
clrscr();
float tm;
int i,ma;
stud st;
res rt;
ofstream gpj("stud.dat",ios::binary|ios::trunc);
ofstream jpg("result.dat",ios::binary|ios::trunc);
if(!gpj||!jpg)
cout<<"File Cannot Be Created"<<endl;
int n;
if(gpj&&jpg)
{
cout<<"How mamy Students U Want to Enter ???? "<<endl;
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter Name"<<endl;
gets(st.name);
cout<<"Enter Roll No"<<endl;
cin>>st.rno;
cout<<"Enter Class"<<endl;
cin>>st.cls;
for(ma=0;ma<5;ma++)
{
cout<<"Enter Marks in subj"<<ma+1<<endl;
cin>>st.marks[ma];
}
gpj.write((char*)&st,sizeof(st));
tm=st.marks[0]+st.marks[2]+st.marks[1]+st.marks[3]+st.marks[4];
rt.perc=tm/5;
if(rt.perc>=75)
rt.grade='A';
if((rt.perc>=60)&&(rt.perc<75))
rt.grade='B';
if((rt.perc>=50)&&(rt.perc<60))
rt.grade='C';
if((rt.perc>=40)&&(rt.perc<50))
rt.grade='D';
if(rt.perc<40)
rt.grade='F';
rt.rnos=st.rno;
jpg.write((char*)&rt,sizeof(rt));
}}
gpj.close();
jpg.close();
int r,k=0;
ifstream god("result.dat",ios::binary);
if(!god)
{
cout<<"File Erroe"<<endl;
}
else
{
god.seekg(0);
cout<<endl<<"ENTER ROLL NO"<<endl;
cin>>r;
while(god.read((char*)&rt,sizeof(rt)))
{
if(r==rt.rnos)
{
k++;
cout<<" Roll no :"<<rt.rnos<<endl<<" Percentage :"<<rt.perc<<endl<<" Grade :"<<rt.grade;
}
}
if(k==0)
cout<<"Roll no not present"<<endl;
god.close();
}
getch();
}
Store text to file
Click Here To Download C++ File Of This Program
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<stdio.h>
#include<fstream.h>
#include<stdlib.h>
#include<string.h>
#include<iomanip.h>
#include<ctype.h>
void main()
{
clrscr();
int i,l;
char st[50];
ofstream t1("lower.txt");
ofstream t2("upper.txt");
if(t1&&t2)
{
cout<<"ENTER "<<endl;
gets(st);
l=strlen(st);
for(i=0;i<l;i++)
{
if(islower(st[i]))
t1<<st[i];
if(isupper(st[i]))
t2<<st[i];
}
}
getch();
}
Telephone Directory ( Structure )
Click Here To Download C++ File Of This Program
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
struct name
{char first[50],mid[50],last[50];};
struct phone
{char area[50],exch[50];
long no;};
class rec
{name n;
phone p;
public :
void reci();
void disp();
};
void rec::reci()
{
clrscr();
cout<<"Enter First Name :";
cin>>n.first;
cout<<endl;
cout<<"Enter Mid Name :";
cin>>n.mid;
cout<<endl;
cout<<"Enter Last Name :";
cin>>n.last;
cout<<endl;
cout<<"Enter Area :";
cin>>p.area;
cout<<endl;
cout<<"Enter Exchange :";
cin>>p.exch;
cout<<endl;
cout<<"Enter No :";
cin>>p.no;
}
void rec::disp()
{
clrscr();
cout<<endl;
cout<<endl;
cout<<"First Name :";
cout<<n.first;
cout<<endl;
cout<<endl;
cout<<"Mid Name :";
cout<<n.mid;
cout<<endl;
cout<<endl;
cout<<"Last Name :";
cout<<n.last;
cout<<endl;
cout<<endl;
cout<<"Area :";
cout<<p.area;
cout<<endl;
cout<<endl;
cout<<"Exchange :";
cout<<p.exch;
cout<<endl;
cout<<endl;
cout<<"No :";
cout<<p.no;
cout<<endl;
cout<<endl;
getch();
}
void main()
{
rec t;
t.reci();
t.disp();
getch();
}
Stack as an Array
Click Here To Download C++ File Of This Program
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
clrscr();
int ch,i,top=-1,stack[5];
x:
cout<<endl<<endl;
cout<<"Enter Choice 1> Insert 2> Delete 3>exit "<<endl;
cin>>ch;
switch(ch)
{
case 1:
top++;
if(top<=4)
{
cout<<"Enter The Element"<<endl;
cin>>stack[top];
cout<<"The Stack is"<<endl;
for(i=0;i<=top;i++)
cout<<stack[i];
goto x;
}
else
{
cout<<" ************* Stack OVERFLOW ********** "<<endl;
goto x;}
case 2:
if(top>=0)
{
top--;
cout<<"Stack is"<<endl;
for(i=0;i<=top;i++)
cout<<stack[i];
goto x;
}
else
{
cout<<"************** Stack UNDER FLOW ***********"<<endl;
goto x;
}
case 3:
exit(0);
default :
cout<<"WRONG CHOICE !!!!!!!!!!! "<<endl;
goto x;
}
}
Salary Sort
Click Here To Download C++ File Of This Program
//SALARY ORDER
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
struct employee
{
int eno;
char name[25];
float salary;
}e[10];
void main()
{
clrscr();
int n;
void bubb(employee,int);
cout<<"Enter No of Employees"<<endl;
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"Enter Employee Name :";
gets(e[i].name);
cout<<endl<<"Enter Employee Code :";
cin>>e[i].eno;
cout<<endl<<"Enter Employee Salary :";
cin>>e[i].salary;
}
bubb(e[10],n);
getch();
}
void bubb(employee e,int n)
{
employee x;
for(int j=0;j<n;j++)
{
if(e[j].salary<e[j+1].salary)
{
for(int i=j;i<n-1;i++)
{
x=e[i];
e[i]=e[i+1];
e[i+1]=x;
}
}
}
for(int i=0;i<n;i++)
{
cout<<endl;
cout<<e[i].name<<endl<<e[i].salary<<endl<<e[i].eno;
}
}
Queue as an Array
Click Here To Download C++ File Of This Program
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
clrscr();
int ch,i,rear=-1,front=-1,queue[10];
x:
cout<<endl<<endl;
cout<<"Enter Choice 1> Insert 2> Delete 3>exit "<<endl;
cin>>ch;
switch(ch)
{
case 1:
if(front==-1)
{front=0;}
rear++;
if(rear<=9)
{cout<<"Enter The Element"<<endl;
cin>>queue[rear];
cout<<"Queue is"<<endl;
for(i=0;i<=rear;i++)
{cout<<queue[i];}
}
else
{cout<<"****************QUEUE OVERFLOW****************";
}
goto x;
case 2:
if(rear==-1)
{rear=0;}
if(front==-1)
{cout<<"*************** UNDER FLOW **********"<<endl;goto x;}
else
if(rear==front)
{queue[front]='\o';
front=-1;
rear=-1;
goto x;
}
else
{queue[front]='\o';
front++;
}
cout<<"Queue is"<<endl;
for(i=0;i<=rear;i++)
{cout<<queue[i];}
goto x;
case 3:
exit(0);
default :
goto x;
}}
Publications ( Classes )
Click Here To Download C++ File Of This Program
//Prg to keep record of books & Audio Cassetes
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<stdio.h>
class publication
{
char title[20];
float price;
public:
void getdata()
{
cout<<"Enter Title"<<endl;
gets(title);
cout<<"Enter Price"<<endl;
cin>>price;
}
void putdata()
{
cout<<"Title"<<endl;
puts(title);
cout<<"Price"<<endl;
cout<<price;
}};
class book : protected publication
{
int pagecount;
public:
void putdata()
{
publication :: putdata();
cout<<endl<<"Pg Count"<<endl;
cout<<pagecount;
}
void getdata()
{
publication::getdata();
cout<<"Pg Count"<<endl;
cin>>pagecount;
}
};
class tape : protected publication
{
float time;
public:
void getdata()
{
publication :: getdata();
cout<<"Enter Time"<<endl;
cin>>time;
}
void putdata()
{
publication :: putdata();
cout<<endl<<"Time "<<endl;
cout<<time;
}
};
void main()
{
clrscr();
book b;
tape t;
int ch;
x:
{
cout<<endl<<"1. BOOK 2:Tape 3:Exit "<<endl;
cin>>ch;
switch(ch)
{
case 1:b.getdata();
b.putdata();
goto x;
case 2:t.getdata();
t.putdata();
goto x;
case 3:exit(0);
}
}
getch();
}
Merge two Arrays
Click Here To Download C++ File Of This Program
//prg to merge arrays
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
int c[100],i,j,k;
class merged
{
int na,nb,a[50],b[50];
public:
void merge();
void display();
void input();
}g;
void merged::merge()
{
int j=0;
int i=na-1;
while((i>0)&&(j<nb))
{
if (b[j]<a[i])
{
c[k]=a[i];
i--;
k++;
}
if (b[j]>a[i])
{
c[k]=b[j];
j++;
k++;
}
if (b[j]==a[i])
{
c[k]=b[j];
j++;
k++;
c[k]=a[i];
i--;
k++;
}
}
if(i==-1)
{
while(j<nb)
{
c[k]=b[j];
j++;
k++;
}
}
if(j==nb)
{
while(i>=0)
{
c[k]=a[i];
i--;
k++;
}
}
}
void merged::display()
{
for(i=0;i<na+nb;i++)
cout<<c[i];
}
void merged::input()
{
cout<<"Enter A Lim"<<endl;
cin>>na;
cout<<"Enter B Limit"<<endl;
cin>>nb;
cout<<"Enter array A"<<endl;
for(i=0;i<na;i++)
cin>>a[i];
cout<<"Enter Array B"<<endl;
for(j=0;j<nb;j++)
cin>>b[j];
}
void main()
{
clrscr();
g.input();
g.merge();
g.display();
getch();
}
Matrix Multiplication
Click Here To Download C++ File Of This Program
//Multiplication of Matrix
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
class matrix
{
int x[10][10];
int m,n;
public:
void input();
void output();
void multiply(matrix,matrix);
};
void matrix::input()
{
cout<<"Enter Row"<<endl;
cin>>m;
cout<<"Enter Column"<<endl;
cin>>n;
cout<<"Matrix"<<endl;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cin>>x[i][j];
}
}
}
void matrix :: output()
{
for(int i=0;i<m;i++)
{
cout<<endl;
for(int j=0;j<n;j++)
{
cout<<x[i][j]<<" ";
}
}
}
void matrix :: multiply(matrix m1, matrix m2)
{
for(int i=0;i<m1.m;i++)
{
for(int j=0;j<m2.n;j++)
{
x[i][j]=0;
for(int k=0;k<m1.n;k++)
{
x[i][j]=x[i][j] +( m1.x[i][k] * m2.x[k][j]);
m=m1.m;
n=m2.n;
}
}
}
}
void main()
{
clrscr();
matrix m1,m2,m3;
m1.input();
m2.input();
m3.multiply(m1,m2);
m3.output();
getch();
}
Subscribe to:
Posts (Atom)