ads

10. WRITE A PROGRAM TO IMPLEMENT DATA FLOW AND CONTROL FLOW ANALYSIS

 

#include<conio.h>

#include<stdio.h>

#include<stdlib.h>

struct stack

{

int no;

struct stack *next;

}

*start=NULL;

typedef struct stack st;

void push();

int pop();

void display();

void main()

{

char ch;

int choice,item;

do

{

           

printf("\n1.push");

printf("\n2.pop");

printf("\n3.display");

printf("\n enter your choice");

scanf("%d",&choice);

switch(choice)

{

case 1:push();

break;

case 2:pop();

break;

case 3:display();

break;

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

}

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

fflush(stdin);

scanf("%c",&ch);

}

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

}

void push()

{

st* node;

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

printf("Enter the numbers to be inserted:::::::");

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

node->next=start;

start=node;

}

int pop()

{

st*temp;

temp=start;

if(start==NULL)

{

printf("stack is already empty");

exit(0);

}

else

{

start=start->next;

free(temp);

}

printf("The deleted element is %d",temp->no);

return(temp->no);

}

void display()

{

st*temp;

temp=start;

while(temp->next!=NULL)

{

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

temp=temp->next;

}

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

}

 

OUTPUT:


No comments:

Post a Comment