Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #246

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Linear.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

#include<iostream.h>
#include<conio.h>
int main()
{
int arr[10], i, num, n, c=0, pos;
cout<<"Enter the array size : ";
cin>>n;
cout<<"Enter Array Elements : ";
for(i=0; i<n; i++)
{
cin>>arr[i];
}
cout<<"Enter the number to be search : ";
cin>>num;
for(i=0; i<n; i++)
{
if(arr[i]==num)
{
c=1;
pos=i+1;
break;
}
}
if(c==0)
{
cout<<"Number not found..!!";
}
else
{
cout<<num<<" found at position "<<pos;
}
return 0;
}
25 changes: 25 additions & 0 deletions prime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <stdio.h>
int main()
{
int n, i, flag = 0;

printf("Enter a positive integer: ");
scanf("%d",&n);

for(i=2; i<=n/2; ++i)
{
// condition for nonprime number
if(n%i==0)
{
flag=1;
break;
}
}

if (flag==0)
printf("%d is a prime number.",n);
else
printf("%d is not a prime number.",n);

return 0;
}
151 changes: 151 additions & 0 deletions stackoperations.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@


Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int st[100],ch,top=-1,size,n,i;
clrscr();
printf("Enter the size of stack:");
scanf("%d",&size);
do
{
printf("\nChoose an option:");
printf("\n1.Push");
printf("\n2.Pop");
printf("\n3.Peek");
printf("\n4.Display");
printf("\n5.Exit\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("\nTo Push:\n");
if(top==size-1)
printf("\nStack Full\n");
else
{
printf("\nEnter the element:\n");
scanf("%d",&n);
top=top+1;
st[top]=n;
printf("\nOperation Successful..!!\n");
}
break;
}
case 2:
{
printf("\nTo pop\n");
if(top==-1)
printf("\nStack Empty\n");
else
{
printf("\nElement Deleted:%d\n",st[top]);
top=top-1;
printf("\nOperation Successful...!!\n");
}
break;
}
case 3:
{
printf("\nTo Peek\n");
if(top==-1)
printf("\nStack Empty\n") ;
else
{
printf("Element is:%d",st[top]);
}
break;
}
case 4:
{
printf("\nTo Display\n");
if(top==-1)
printf("\nStack Empty\n");
else
{
printf("\nElements of stack are:\n");
for(i=0;i<=top;i++)
printf("%d\n",st[i]);
printf("\n");
}
break;
}
case 5:
{
printf("\nExit\n");
break;
}
default:
printf("\nOOPS!! Wrong value\n");
}
}while(ch!=5);

getch();
}


Output
Choose an option:
1.Push
2.Pop
3.Peek
4.Display
5.Exit
1

Enter the Element
23
Operation Successful...!!


Choose an option:
1.Push
2.Pop
3.Peek
4.Display
5.Exit
3

To Peek

Element is:23


Choose an option:
1.Push
2.Pop
3.Peek
4.Display
5.Exit
2

Element Deleted :23

Operation Successful...!!

Choose an option:
1.Push
2.Pop
3.Peek
4.Display
5.Exit
4

To Display

Stack Empty

Choose an option:
1.Push
2.Pop
3.Peek
4.Display
5.Exit
5

Exit