0% found this document useful (0 votes)
51 views

Computer

The document contains a list of 28 programming problems covering topics like calculating student marks percentage, finding the largest of three numbers, checking if a number is palindrome, implementing linear and binary search in an array, and implementing stack and queue operations using arrays and linked lists. The problems are about writing C/C++ programs to perform various tasks like calculations, conditional checking, searching and sorting arrays, and implementing basic data structures.

Uploaded by

Chandan Patra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Computer

The document contains a list of 28 programming problems covering topics like calculating student marks percentage, finding the largest of three numbers, checking if a number is palindrome, implementing linear and binary search in an array, and implementing stack and queue operations using arrays and linked lists. The problems are about writing C/C++ programs to perform various tasks like calculations, conditional checking, searching and sorting arrays, and implementing basic data structures.

Uploaded by

Chandan Patra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

CONTENTS

S.NO

TOPIC

1.

Writ_ [ ]++ progr[m th[t input's [ stu^_nt's m[rks in fiv_


su\j_]ts (out of 100) [n^ print th_ p_r]_nt[g_

2.

Writ_ [ progr[m to fin^ l[rg_st of thr__ num\_rs

3.

Writ_ [ progr[m to print th_ Fi\on[]]i s_ri_s of sp_]ifi_^


t_rms

4.

Writ_ [ progr[m to ]h_]k wh_th_r [ y_[r is [ l_[p y_[r


or not

5.

Writ_ [ progr[m to ]h_]k wh_th_r [ num\_r is p[lin^rom_


or not

6.

Writ_ [ progr[m to ]h_]k wh_th_r th_ num\_r is prim_ or


not

7.

Writ_ [ progr[m to sw[p two num\_rs

8.

Writ_ [ progr[m to sw[p two strings

9.

Writ_ [ progr[m to ][l]ul[t_ th_ string l_ngth

10.

Writ_ [ progr[m to fin^ p[lin^rom_ of [ string

11.

Writ_ [ progr[m to fin^ th_ m[ximum _l_m_nt in [n [rr[y

12.

writ_ [ progr[m to _nt_r to ins_rt [n _l_m_nt in [n [rr[y

13.

Writ_ [ progr[m to ^_l_t_ [n _l_m_nt in [n [rr[y

14.

Writ_ [n progr[m to impl_m_nt lin_[r s_[r]h in [n [rr[y


list

15.

Writ_ [ progr[m to impl_m_nt \in[ry s_[r]h in [n [rr[y


list

16.

Writ_ [ progr[m to [rr[ng_ _l_m_nts of [n [rr[y list in


[s]_n^ing or^_r using \u\\l_ sort

17.

Writ_ [ progr[m to [rr[ng_ _l_m_nts of [n [rr[y list


in [s]_n^ing or^_r using ins_rtion sort

18.

Writ_ [ progr[m to [^^ two m[tri]_s.

19.

Writ_ [ progr[m to multiply two m[tri]_s

20.

Writ_ [ progr[m to tr[nspos_ two m[tri]_s

21.

Writ_ [ progr[m to ]r_[t_ [ fil_ using fil_ str_[m

22.

Writ_ [ progr[m to writ_ [n^ r_[^ in [ t_xt fil_


n[m_^ s[mpl_.txt.

23.

Writ_ [ progr[m to ^_monstr[t_ _x[mpl_ of tellg()


[n^ tellp() fun]tions

24.

@ssuming th[t [ t_xt fil_ n[m_^ FIRST.TXT ]ont[ins


som_ t_xt writt_n into it, writ_ [ fun]tion n[m_^
]opyupp_r(), th[t r_[^s th_ fil_ FIRST.TXT [n^
]r_[t_s [ n_w fil_ n[m_^ SECOND.TXT ]ont[ins [ll
wor^s from th_ fil_ FIRST.TXT in upp_r][s_

25.

W@P to st[]k op_r[tion on [n [rr[y.

26.

W@P in C++ to impl_m_nt qu_u_ [s [n [rr[y.

27.

W@P to impl_m_nt st[]k [s [ link_^ list.

28.

W@P to impl_m_nt qu_u_ [s [ link_^ list.

29.

SQL COMM@NDS

25. W@P to st[]k op_r[tion on [n [rr[y.


#include<iostream.h>
#include<conio.h>
#include<process.h>
int pop(int[],int&);
int push(int[],int&,int);
void display(int[],int);
const int size=50;
void main()
{
clrscr();
char m,ch;
int k,stack[size],item,top=-1,res;
do
{

cout<<"\nChoose from the following : \n\n"


<<"\n 1. Push"
<<"\n 2. Pop"
<<"\n 3. Display"
<<"\n 4. Exit"
<<"\n\nEnter your choice : "; cin>>k;

switch(k)
{
case 1: ch='y';

while(ch=='y'||ch=='Y')
{ cout<<"\nEnter the element : ";
cin>>item;
res=push(stack,top,item);
if(res==-1)
{cout<<"\nOverflow !!!!";
exit(1); }
cout<<"\nThe stack formed is : \n\n";
display(stack,top);
cout<<"\n\n\nWant to enter again ?: ";
cin>>ch;
}
break;

case 2: ch='y';
while(ch=='y'||ch=='Y')
{ res=pop(stack,top);
if(res==-1)
{
cout<<"\nUnderflow !!!!";
exit(1);
}
else
{
cout<<"\nThe deleted Element is : "<<res<<endl;

cout<<"\nThe resultant stack is : \n\n";


display(stack,top); }
cout<<"\nWant to delete again ? : ";
cin>>ch;
}
break;
case 3: cout<<"\nThe resultant stack is : ";
display(stack,top);
break;

case 4: exit(0);
break;

default: cout<<"\nPlease enter desired keyword : ";


}

// end of switch

cout<<"\n\nChoose from the menu again ? : ";


cin>>m;

}while(m=='y'||m=='Y');

// end of do-while loop

getch();
}

int push(int stack[],int &top,int el)


{

// end of main()

if(top==size-1)
return -1;
else
{
top++;
stack[top]=el;
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)


{

cout<<sttack[top]<<"<--";
ffor(int i=ttop-1;i>=0;i--)
ccout<<staack[i]<<"<--";
}

O
Outputt

26. W@P in C++ to impl_m_nt qu_u_ [s [n [rr[y.

#include<iostream.h>
#include<conio.h>
#include<process.h>
const int size=50;
int q[size],rear=-1,front=-1;
int insert(int q[],int ele)
{
if(rear==size-1)
return(-1);
else if(rear==-1)
{
front=rear=0;
q[rear]=ele;
}
else
{
rear++;
q[rear]=ele;
}
return(0);
}
int delet(int q[])
{
int r ;
if(front==-1)
return(-1);
else
{
r=q[front];
if(rear==front)
front=rear=-1;
else
front++;
}
return r;
}
void display(int q[],int front,int rear)
{

if(front==-1)
return;
else
{
for(int i=front;i<=rear;i++)
cout<<q[i]<<" ";
}
}
void main()
{
clrscr();
int n,u,k,m;
char ch,ans;
do
{
cout<<"\nChoose from the menu :\n"
<<"\n 1. Insert"
<<"\n 2. Delete"
<<"\n 3. Display"
<<"\n\n Enter your choice : "; cin>>n;
switch(n)
{
case 1: ans='y';
while(ans=='y'||ans=='Y')
{
cout<<"\n Enter element to be inserted :"; cin>>m;
k=insert(q,m);
if(k==-1)
cout<<"\n Overflow !!!!";
cout<<"\n The resultant Queue is : ";
display(q,front,rear);
cout<<"\n\n Want to enter again ?: ";
cin>>ans;
}
break;
case 2: ans='y';
while(ans=='y'||ans=='Y')
{
u=delet(q);
if(u==-1)

{
nderflow !!!!";
cout<<"\n Un
breakk;
}
ellse
{
he deleted
d element is "<<u<<"\n";
cout<<"\n Th
he resultant Queue is : \n\n"";
cout<<"\n Th
displlay(q,front,rear);
}
cout<<"\n\n Waant to deleete again ?: ";
ns;
cin>>an
}
break;
case 3: cout<<"\
\n The Quueue is : \n
n\n";
d
display(q,f
front,rear));
b
break;
default: cout<<"\
\n Please enter desiired keyw
word : ";
}
cout<<"\n Choose from th
he menu aagain ? : ";cin>>ch;
while(ch=
=='y'||ch=
=='Y');
}w
getch());
}

O
OUTPUT
T

27. W@P to impl_m_nt st[]k [s [ link_^ list.


#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node {
int roll;
node* next;
}*top,*save,*ptr,*newptr,*np;
node *create(int a)
{
ptr=new node;
ptr->roll=a;
ptr->next=NULL;
return ptr;
}
void push(node *np)
{
if(top==NULL)
top=np;
else
{
save=top;
top=np;
np->next=save;
}
}
void pop()
{
if(top==NULL)
cout<<"\n Underflow!!!!";
else
{
ptr=top;
top=top->next;
delete ptr;
}
}
void display(node *np)
{
while(np!=NULL)

{
cout<<np->roll<<" -> ";
np=np->next;
}
}
void main()
{
clrscr();
top=NULL;
int n,m;
char k,ch;
do {
cout<<"\nChoose from the menu :\n"
<<"\n 1. Push."
<<"\n 2. Pop."
<<"\n 3. Display."
<<"\n 4. Quit."
<<"\n\nEnter your choice : ";
cin>>n;
switch(n)
{
case 1: k='y';
while(k=='y'||k=='Y')
{
cout<<"\n Enter element to be inserted .";
cin>>m;
newptr=create(m);
if(newptr==NULL)
cout<<"\n Cannot create !!!!";
push(newptr);
cout<<"\n The Stack formed is : ";
display(top);
cout<<"\n\n Want to enter again ?: ";
cin>>k;
}
break;
case 2: k='y';
while(k=='y'||k=='Y')
{

pop();
med is : \n
n\n";
cout<<"\n The SStack form
display((top);
cout<<"\n\n Waant to deleete again ?: ";
cin>>k;;
}
b
break;
case 3: cout<<"\
\n The Staack formeed is : ";
display(top
d
p);
b
break;
case 4: exit(0);
b
break;
default: cout<<"\
\n Please enter desiired keyw
word : ";
}
ccout<<"\\n Do you want to ccontinue..? : ";
ccin>>ch;
while(ch=
=='y'||ch=
=='Y');
}w
getch();
}

O
Outputt

28. W@P to impl_m_nt qu_u_ [s [ link_^ list.


#include<iostream.h>
#include<conio.h>
struct node {
int roll;
node* next;
}*front,*rear,*ptr,*newptr,*np;
node *create(int a)
{
ptr=new node;
ptr->roll=a;
ptr->next=NULL;
return ptr;
}
void insert(node *np)
{
if(front==NULL)
front=rear=np;
else
{
rear->next=np;
rear=np;
}
}
void delet()
{
if(front==NULL)

cout<<"\n Underflow!!!!";
else
{
ptr=front;
front=front->next;
delete ptr;
}
}
void display(node *np)
{
while(np!=NULL)
{
cout<<np->roll<<"-> ";
np=np->next;
}
}
void main()
{
clrscr();
front=rear=NULL;
int n,m;
char ans,ch;
do
{ cout<<"\nChoose from the menu : "
<<"\n 1) Insert."
<<"\n 2) Delete
<<"\n 3) Display."
<<"\n\n Enter your choice : ";
cin>>n;

switch(n)
{
case 1: ans='y';
while(ans=='y'||ans=='Y')
{
cout<<"\n Enter element to be inserted .";
cin>>m;
newptr=create(m);
if(newptr==NULL)
cout<<"\n Cannot create !!!!";
insert(newptr);
cout<<"\n The Queue formed is : ";
display(front);
cout<<"\n Want to enter more nodes ?: ";
cin>>ans;
}
break;
case 2: ans='y';
while(ans=='y'||ans=='Y')
{
delet();
cout<<"\n Queue : ";
display(front);
cout<<"\n Want to delete more ?: ";

cin>>an
ns;
}
b
break;
case 3: cout<<"\
\n Queue : ";
d
display(fro
ont);
b
break;
default: cout<<"\
\n You en
ntered wroong choicee...";
}
ccout<<"\\n Want to return tto main menu
m
? : ";
ccin>>ch;
}w
while(ch=
=='y'||ch=
=='Y');
getch();
}

O
Outputt

You might also like