Docsity

Data Structures and Algorithms: C Programming Exercises, Exams of Data Structures and Algorithms

Partial preview of the text

Download Data Structures and Algorithms: C Programming Exercises and more Exams Data Structures and Algorithms in PDF only on Docsity!

DATA STRUCTURE

ASSIGNMENT

NAME:R.SURESH

REG.NO:BU

SUBJECT:B.SC.CS

SUBMITTEDBY:

M.SERLINRAJ(proffessor)

1. Develop a C program for following out using

singly linked list.

Enter a Number:

Want to Continue[y/n]: y

Enter a Number: 34

Want to Continue[y/n]: y

Enter a Number: 44

Want to Continue[y/n]: n

The Values of the Linked list are:

24 34 44

PROGRAM:

#include<stdio.h>

struct node

int number;

struct node *p;

}h,f,*t;

main()

char c;

f=NULL;

do

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

printf(“\n enter the number”);

scanf(“%d”,&h->number);

if(f!=NULL)

t->p=h;

t=h;

else f=t=h;

fflush(stdin);

printf(“\n Continue (Y/N):”);

scanf(“%c”,&c);

while(c==’Y’)

t->p=NULL;

t=f;

printf(“\n the list elements are: ”);

while(t!=NULL)

printf(“%d”,t->number);

t=t->p;

float f=0,i; for(i=0;i<n;i++) { f=f+(p); p++; } return (f/n); } void main() { int a[10],i,p; float avg; printf("Enter the no. of Subject: "); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter the Subject-%d Marks= ",i+1); scanf("%d",&a[i]); } p=a; avg=average(p); printf("the average marks = %f",avg); }