Sei sulla pagina 1di 42

#include<stdio.

h>

#include<conio.h>

int main()

FILE *fp,fn;

char ch;

int w,v,c,s;

printf("Enter any file name ");

gets(fn);

fp=fopen("test.txt","r");

if(fp==NULL)

printf("\n file not found \n ");

getch();

exit(1);

else

printf("\n this part for read from the file \n ");


while((ch=getc(fp))!=EOF)

printf("%c",ch)

if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'|
|ch=='I'||ch=='O'||ch=='U'||)

v++;

else if(ch==' ')

s++;

else

c++;

w=s+1;

}
fclose(fp);

printf("\n Number of vowel is %d",v);

printf("\n Number of consonent is %d",c);

printf("\n Number of word is %d",w);

printf("\n Number of blank space is %d",s);

getch();

}
#include<stdio.h>

#include<conio.h>

#include<malloc.h>

#define p printf

struct node

int data;

struct node *next;

}*start=NULL,*temp,*new_node,*pre;

void insert()

{ //

int i,d,po,j;

p("\n1>insert at begining\n2>insert at end\n3>Insert at


middle\nEnter your choice-->");

scanf("%d",&i);

printf("enter data : ");

scanf("%d",&d);

new_node=(struct node *)malloc(sizeof(struct node) );

new_node->data=d;
switch(i)

case 1: // insert at the begining //

new_node->next=start;

start=new_node;

break;

case 2: // insert at the end //

new_node->next=NULL;

temp=start;

while(temp->next!=NULL)

temp=temp->next;

temp->next=new_node;

break;

case 3:

// insert at any position

temp=start;

p("enter the position -->");

scanf("%d",&po);
j=1;

while(j<po-1)

temp=temp->next;

j++;

new_node->next=temp->next;

temp->next=new_node;

break;

default:

p("\n invalid insert option.");

void del()

int i,po,j;

p("\n1>delete at begining\n2>delete at end\n3>delete at


middle\nEnter your choice-->");

scanf("%d",&i);

switch(i)
{

case 1:

temp=start;

start=temp->next;

free(temp);

break;

case 2:

temp=start;

pre=start;

while(temp->next!=NULL)

pre=temp;

temp=temp->next;

pre->next=NULL;

free(temp);

break;

case 3:

temp=start;

pre=start;
p("\nenter the position ");

scanf("%d",&po);

j=1;

while(j<po)

pre=temp;

temp=temp->next;

j++;

pre->next=temp->next;

free(temp);

break;

default:

p("\n invalid delete option.");

void show()

temp=start;
while(temp!=NULL)

p("%d->",temp->data);

temp=temp->next;

void create()

{ // to create the link list.

char a;

int d=0;

do

new_node=(struct node *)malloc(sizeof(struct node) );

p("enter a value : ");

scanf("%d",&d);

new_node->data=d;

if(start==NULL)

start=new_node;

new_node->next=NULL;
}

else

temp=start;

while(temp->next!=NULL)

temp=temp->next;

new_node->next=NULL;

temp->next=new_node;

p("\nDo u want to continue?");

fflush(stdin);

scanf("%c",&a);

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

int main()

int n;
while(1)

p("\n1)create\n2)show\n3)insert\n4)delete\n5)exit\nEnter
your choice : ");

scanf("%d",&n);

switch(n)

case 1:

create();

break;

case 2:

show();

break;

case 3:

insert();

break;

case 4:

del();
break;

case 5:

return 0;

default:

p("invalid input.");

getch();

}
#include<stdio.h>

#include<malloc.h>

#include<conio.h>

struct link

int coe;

int p;

struct link *next;

};

struct link *poly1=NULL,*poly2=NULL,*poly=NULL;

void create(struct link *node)

char ch;

do

printf("\n enter coeff:");

scanf("%d",&node->coe);

printf("enter power:");

scanf("%d",&node->p);
node->next=(struct link*)malloc(sizeof(struct link));

node=node->next;

node->next=NULL;

printf("\n continue(y/n):");

ch=getch();

while(ch=='y' || ch=='Y');

//function to sidplay the polinomials equation

void show(struct link *node)

while(node->next!=NULL)

printf("%dx^%d",node->coe,node->p);

node=node->next;

if(node->next!=NULL)

printf("+");

}
void polyadd(struct link *poly1,struct link *poly2,struct link *poly)

while(poly1->next && poly2->next)

if(poly1->p>poly2->p)

poly->p=poly1->p;

poly->coe=poly1->coe;

poly1=poly1->next;

else if(poly1->p<poly2->p)

poly->p=poly2->p;

poly->coe=poly2->coe;

poly2=poly2->next;

else

poly->p=poly1->p;

poly->coe=poly1->coe+poly2->coe;
poly1=poly1->next;

poly2=poly2->next;

poly->next=(struct link *)malloc(sizeof(struct link));

poly=poly->next;

poly->next=NULL;

while(poly1->next || poly2->next)

if(poly1->next)

poly->p=poly1->p;

poly->coe=poly1->coe;

poly1=poly1->next;

if(poly2->next)

poly->p=poly2->p;

poly->coe=poly2->coe;

poly2=poly2->next;
}

poly->next=(struct link *)malloc(sizeof(struct link));

poly=poly->next;

poly->next=NULL;

void main()

clrscr();

poly1=(struct link *)malloc(sizeof(struct link));

poly2=(struct link *)malloc(sizeof(struct link));

poly=(struct link *)malloc(sizeof(struct link));


printf("\nenter 1st number:");

create(poly1);

printf("\nenter 2nd number:");

create(poly2);

printf("\n1st Number:");

show(poly1);
printf("\n2nd Number:");

show(poly2);

polyadd(poly1,poly2,poly);

printf("\nAdded polynomial:");

show(poly);

getch();

}
#include<stdio.h>

#include<conio.h>

#define max 5

int front=-1,rear=-1;

int queue[max];

void insert()

int item;

int ch;

if(rear==max-1)

printf("\n The queue is full ");

else

do

if(front==-1)

{
front++;

rear++;

printf("\n enter the element ");

scanf("%d",&item);

queue[rear]=item;

else

rear=rear+1;

printf("\n enter the element ");

scanf("%d",&item);

queue[rear]=item;

printf("\n Do you want to continue (1/2) ");

scanf("%d",&ch);

} while(ch==1);

void delet()

{
int item;

if(front<0)

printf("\n The queue is underflow ");

getch();

else

item=queue[front];

printf("\n The deleted element is %d",item);

front=front+1;

void display()

int i;

if(front==-1)

printf("\n The queue is empty ");

getch();
}

else

printf("\n The queue is \n ");

for(i=front;i<=max-1;i++)

printf(" \n queue[%d]= %d ",i,queue[i]);

int main()

int choice;

while(1)

printf("\n\n 1> insert \n 2> delet \n 3> display \n 4> exit\n


");

printf("\n Enter your choice ");

scanf("%d",&choice);
switch(choice)

case 1:

insert();

break;

case 2:

delet();

break;

case 3:

display();

break;

case 4:

return 0;

}
#include<stdio.h>

#include<conio.h>

#define MAX 10

struct queue

int info[MAX];

int front,rear;

};

typedef struct queue Q;

void insert(Q*,int);

void display(Q*p);

void del(Q*);

int main()

Q q;

int i,x,item;

q.front=q.rear=-1;

do
{

printf("\n1:insert 2:delete 3:display 4:exit");

printf("\n enter the choice");

scanf("%d",&i);

switch(i)

case 1:printf("\n give an element to insert");

scanf("%d",&x);

insert(&q,x);

break;

case 2:del(&q);

break;

case 3:display(&q);

break;

case 4:printf("\n the end");

return 0;

default:

printf("\n invalid option");

break;

}
}while(i!=4);

void insert(Q*p,int item)

if(p->rear==MAX-1)

printf("\nqueue is overflow");

return;

p->info[++p->rear]=item;

void del(Q*p)

if(p->front==p->rear)

printf("\nqueue underflow");

return;
}

printf("\n the deleted element is %d",p->info[++p->front]);

void display(Q*p)

if(p->front==p->rear)

printf("\n queue underflow");

return;

while(p->rear!=p->front)

printf("\n the list is %d",p->info[++p->front]);

}
#include<stdio.h>

#include<conio.h>

int main()

char ans;

int no[4],cho;

int i=0,j=-1,k=3,num;

int x;

do

printf("\n\tSTACK
REPRESENTATION\n\t1.PUSH\n\t2.POP\n\t3.SHOW\n\t4.EXIT");

printf("\n\tEnter your choice : ");

fflush(stdin);

scanf("%d",&cho);

switch(cho)

{
case 1:

if(j==k)

printf("The Stack Is Full");

else

printf("Enter a number");

scanf("%d",&num);

no[++j]=num;

}
break;

case 2:

if(j>-1)

no[j--]=0;

printf("\n\tThe Stack Popped Successfully");

else
{

printf("\n\tStack Is Empty");

break;

case 3:

printf("The Value In The Stack Are : ");

for(x=0;x<=j;x++)

printf(" %d",no[x]);

if(j<0)

printf("The Stack Is Empty; No Value To Show");

break;

case 4:

printf("Press Any Key To Exit");

getch();
default:

printf("Invalid Choice");

printf("\n\n\tDo You Want To Continue? (y/n)");

fflush(stdin);

ans=getche();

while(ans=='y'||ans=='Y');

getch();

}
#include<stdio.h>

#include<conio.h>

struct stack

int no;

struct stack *next;

*start=NULL;

typedef struct stack st;

void push();

int pop();

void display();

int main()

char ch;

int choice,item;

do
{

printf("\n 1: push");

printf("\n 2: pop");

printf("\n 3: display");

printf("\n Enter your choice");

scanf("%d",&choice);

switch (choice)

case 1: push();

break;

case 2: item=pop();

printf("The delete element in %d",item);

break;

case 3: display();

break;

default : printf("\n Wrong choice");

};

printf("\n do you want to continue(Y/N)");

fflush(stdin);
scanf("%c",&ch);

while (ch=='Y'||ch=='y');

getch();

void push()

st *node;

node=(st *)malloc(sizeof(st));

printf("\n Enter the number to be insert");

scanf("%d",&node->no);

node->next=start;

start=node;

int pop()

st *temp;

temp=start;

if(start==NULL)

{
printf("stack is already empty");

getch();

else

start=start->next;

free(temp);

return(temp->no);

void display()

st *temp;

temp=start;

while(temp->next!=NULL)

printf("\nno=%d",temp->no);

temp=temp->next;

}
printf("\nno=%d",temp->no);

}
#include<stdio.h>

#include<ctype.h>

#include<conio.h>

void main()

char st[100],ch;

int i,v,c,s,sy;

clrscr();

puts("Enter any sentence ");

gets(st);

v=c=s=sy=0;

for(i=0;st[i]!='\0'; i++)

ch=toupper(st[i]);

if(isalpha(ch))

if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')

v++;

else
c++;

else if(ch==' ')

s++;

else

sy++;

printf("\n Total Vowel %d",v);

printf("\n Total Consonent %d",c);

printf("\n Total Space %d",s);

printf("\n Total AlphaNumeric %d",sy);

getch();

}
#include<stdio.h>

#include<conio.h>

char stack[20];

int top=-1;

void push(char x)

Stack[++top]=x;

char pop()

If(top==-1)

return-1;

else

return stack[top--];

Int priority(char x)

If(x==’(‘)
return0;

if(x==’+’||x==’-‘)

return1;

if(x==’*’||x==’/’)

return 2;

return(-1);

void main()

char exp[20];

char*e,x;

clrscr();

printf(“Enter the expression::”);

scanf(“%s”,exp);

e=exp;

while(*e !=’\0’)

if(isalnum(*e))

printf(“%c”,*e);

else if(*e==’(‘)
push(*e);

else if(*e==’(‘)

while((x=pop()) !=’(‘)

printf(“%c”,x);

else

while(priority(stack[top])>=priority(*e))

printf(“%c”,pop());

push(*e);

e++;

while(top !=-1)

printf(“%c”,pop());

getch();

Potrebbero piacerti anche