B[i][j]; } for(i=0;i
cout<<”\nProduct of A and B matrices:”; for(i=0;i
OUTPUT
Input row & column of A matrix: 23 Input row &coloumn of B materx: 32 Matrices can be multiplied. Input matrix-A: 1 2 3 1 2 3 Input matrix-B: 1 2 1 2 1 2 Product of A &B materices: 6 12 6 12
11. PROGRAM TO MERGE THE TWO GIVEN ARRAYS #include
“;
cout<
{ if(A[a]<=B[b]C[c++]=A[a++]; Else{ C[c++]=B[b--]; } if(a
OUTPUT
How many elements do u you want to create first array with?(max.50)…5 Enter first array’s elements [ascending]… 2 5 8 9 12 How many elements do you want to create second array with?(max.50)..7 Enter second array’s elements[descending]… 16 12 10 8 7 3 1 The merged array is shown below… 1 2 3 5 7 8 9 10 12 12 16
12. PROGRAM TO PRINT DIFFERENT VALUES BEING POINTING TO BY AN ARRAY OF THE POINTER #include
ip[2]=&t;
ip[1]=&s;
ip[3]=&fo;
for(int i=0 ;i<4;i++) cout<<"The pointers ip["<
The address stored in ip[3] is 0x22f72450 13. PROGRAM TO POP THE ELEMENT FORM THE ARRAY STACK #include
if(res==-1) { cout<<”UNDERFLOW!!!Aborting!!\n”; exit(1); } else { cout<<”\nWant to delete more elements?...(y/n)\n”; cin>>ch;} return 0; } int push(int stack[ ],int & top,int ele) { if(top==size-1) return-1; else { top++; Stack[top]=ele; } return 0; } int pop(int stack[ ],int&top) { int ret; if (top==-1) return -1; else { ret=stack[top]; top--; } return ret; } void Display(int stack[ ],int top) { if(top==-1) return; cout<
}
OUTPUT Enter ITEM for insertion : 9 The stack now is : 9<-Want to insert more elements?(y/n)...y Enter ITEM for insertion :3 The stack now is : 3<-9 Want to insert more elements ?(y/n)...n Now deletion of elements begins... Element deleted is :3 The stack now is : 9<-Want to delete more elements?(y/n)...n
14. PROGRAM TO PRINT THE PRODUCT OF THE EACH ROW OF THE 2-D ARRAY #include
return 0; }
void prod( ); {int a[10][10],i,j,r,c,prod=1; cout<<”enter no. of rows and columns”; cin>>r>>c; cout<<”enter the array elements”; for(i=0;i
cin>>a[i][j];}
for(i=0;i
OUTPUT Enter no of rows and columns 2 2 Enter the elements of array 10 20 20 20 Product of row 1 = 2000 Product of row 2 = 4000
15. PROGRAM TO PRINT THE LARGEST NUMBER #include
OUTPUT
Enter two integers 7 13 The bigger value is 13
16. PROGRAM TO SHOW PUSHING IN THE LINKED QUEUE #include
return ptr; } void insert_end(node*np) { if (front==NULL)front=rear=np; else {rear->next=np; rear=np; } } void display(Node*np) { while (np!=NULL) {cout<
OUTPUT
Enter INFOrmation for the new node…5 Now the queue(Front…to…Rear)is: 5->!!! Press Y to enter more nodes,N to exit…y Enter INFOrmation for the new node…12 Now the queue(Front…to…Rear)is: 5->12->!!!
Press Y to enter more nodes,N to exit…n 17. PROGRAM TO PRINT THE GLOBAL VARIABLES #include
OUTPUT main() a=15 ::a=10 Inner Block a=25 ::a=10 Back to main() a=15
::a=10 18. PROGRAM TO REVERSE THE ARRAY #include
} int RevAr(Ar[ ],int size) { inti=0,j=size-1,tmp; for(;i<=j,i++,j--) { tmp=Ar[i]; Ar[i]=Ar[j]; Ar[j]=tmp; } return; }
OUTPUT Enter the no. of the elements of the array 8 Enter the array elements 25367341
The Reversed array is 14376352
19. PROGRAM TO SEARCH FOR A GIVEN CHARACTER INSIDE A STRING AND TO PRONT THE STRING FROM THE POINT OF MATCH #include
return(s); }
OUTPUT Enter a string (Max.80 characters ) I like computer science Enter a character to be searched for o
mputer science 20. PROGRAM OF PUSHING THE INFORMATION IN THE STACK #include
Node*create_new_node(int n); { ptr=new node; ptr->info=n; ptr->info=n; ptr->next=null; return ptr; void push(node*np) { if(top==null) Top=np; else { if (top==null) Top=np; else { save=new node; ptr-> info =n; ptr->next=null; return ptr; } void push(node*np) { if(top==null) Top=np; else { save=top; Top=np; np->next=save; } } void display(node*np)
}
{ while(np!=null) {cout<
OUTPUT
Enter INFOrmation for the new node…5 Now the linked-stack is: 5->!!! Press Y to enter more nodes ,N to exit…y Enter INFOrmation for the new node…8 Now the linked-stack is: 8-> 5->!!! Press Y to enter more nodes ,N to exit…y Enter INFOrmation for the new node...3 Now the liked -stack is: 3->8->5->!!!
21. PROGRAM THAT INPUTS A LINE OF TEXT AND A SUBSTRING TO SEARCH FOR .THEN IT SHOULD DISPLAY THE POSITION OF FIRST AND THE LAST POSITION OF THAT SUBSTRING #include
spos=i;break; }
else i=j-1; }
else i++; } int len2=strlen(sub); for(i=len-1;i>=0;) { j=i; if(line[j]==sub[len2-1] {k=len2-1; while(line[j--]==sub[k--]); if(k<0) { lpos=j+2; break; } else i- -; }
OUTPUT
Enter line of text:a string such as this string holds another string even strings in it Enter substrig to find:string First occurance of string is at position 3 Last occurance of string is at position 56
22. PROGRAM TO SHOW TRAVERSAL IN THE ARRAY #include
OUTPUT
How many elements do u want to create an array with?(max.50)…7 Enter array elements… 2 5 7 9 12 20 25 Array with doubled elements is as follows…
4 10 14 18 24 40 50 23. PROGRAM TO SWAP THE VARIBLES USING POINTERS #include
OUTPUT Original values a=7, b=4 Swapped Valus
a=4, b=7 24. PROGRAM TO DISPLAY THE TRANSPOSE OF THE MATRIX #include
return 0;}
OUTPUT
Enter the elements of a matrix: 1 5 6 7 5 3 1 7 9
Given Matrix is: 1 5 6 7 5 3 1 7 9
The transpose of the matrix is: 1 7 1 5 5 7 6 3 9