write a program to find the sum of the array elements in c
language?

Answer Posted / sasa zezo

please help me i can't understand this program?


#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node *create(int n)
{
struct node *head;
head=(struct node*)malloc(sizeof(struct node));
if(head==NULL)
{
printf("no memory space");
exit(0);
}
else
{
head->data=n;
head->next=NULL;
}
return head;
}
void print(struct node * p)
{
printf("\n the new linked list is \n");
while(p!=NULL)
{
printf(" %d \t ",p->data);
p = p->next ;
}
printf("\n");
}
struct node * deletelast(struct node * p)
{
struct node *prev,*curr;
curr=p;
prev=NULL;
while(curr->next!=NULL)
{
prev=curr;
curr=curr->next;
}
prev->next=NULL;
free(curr);
return p;
}
struct node * deletefrst(struct node * p)
{
struct node *curr;
curr=p;
p=p->next;
free(curr);
return p;
}
struct node * deletenode(struct node * p , int x)
{
struct node *prev,*curr;

curr=p;
prev=NULL;
while((curr->data!=x)&&(curr->next!=NULL))
{ prev=curr;
curr=curr->next;}

if((curr->next==NULL)&&(curr->data!=x))
{ printf("the element x is not found");
prev->next=NULL;
free(curr);}
else {
prev->next=curr->next;
free(curr);}
return p;
}
int count(struct node * p)
{
struct node *curr;
int i=0;
curr=p;
while(curr!=NULL)
{
curr=curr->next;
i++;
}
return i;
}
struct node * insertfrst(struct node * p , int n)
{
struct node * temp;
temp=(struct node*)malloc(sizeof(struct node));
if(temp==NULL)
{
printf("no memory space");
exit(0);
}
else
{
temp->data=n;
temp->next=p;
p=temp;
}
return temp;
}
struct node *insertlast(struct node * p,int n)
{
struct node *temp,*curr;
temp=(struct node*)malloc(sizeof(struct node));
if(temp==NULL)
{
printf("no memory space");
exit(0);
}
curr=p;
while(curr->next!=NULL)
{
curr=curr->next;
}
temp->data=n;

temp->next=NULL;
curr->next=temp;
return p;
}

struct node * insertbefor(struct node * p,int n,int x)
{
struct node *temp,*prev,*curr;
temp=(struct node*)malloc(sizeof(struct node));
if(temp==NULL)
{

printf("no memory space");
exit(0);}
curr=p;
prev=NULL;
while((curr->data!=x)&&(curr->next!=NULL))
{ prev=curr;
curr=curr->next;}
if((curr->next==NULL)&&(curr->data!=x))
{ printf("the element x is not found");
temp->data=n;
temp->next=NULL;
curr->next=temp;}
else
{temp->data=n;
temp->next=curr;
prev->next=temp;}
return p;}
void main()
{
struct node * p;
int i;
p=create(20);
print(p);
for( i=1;i<=4;i++)
p=insertfrst(p,i);
print(p);
p=insertlast(p,34);
print(p);
p=insertbefor(p,77,34);
print(p); p=delete¬node(p,34);
print(p);
p=deletelast(p);
print(p);
p=deletefrst(p);
print(p);}

Is This Answer Correct ?    0 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what is the advantage of a random access file?

670


What is a buffer in c?

580


What are 'near' and 'far' pointers?

626


write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.

3343


What is an auto keyword in c?

647






what are bit fields? What is the use of bit fields in a structure declaration?

1503


Wt are the Buses in C Language

2755


what is the c source code for the below output? 5555555555 4444 4444 333 333 22 22 1 1 22 22 333 333 4444 4444 5555555555

2541


Do you know pointer in c?

595


A banker has a seif with a cipher. Not to forget the cipher, he wants to write it coded as following: each digit to be replaced with the difference of 9 with the current digit. The banker chose a cipher. Decipher it knowing the cipher starts with a digit different than 9. I need to write a program that takes the cipher from the keyboard and prints the new cipher. I thought of the following: Take the input from the keyboard and put it into a string or an array. Go through the object with a for and for each digit other than the first, substract it from 9 and add it to another variable. Print the new variable. Theoretically I thought of it but I don't know much C. Could you give me any kind of hint, whether I am on the right track or not?

1516


A function can make the value of a variable available to another by a) declaring the variable as global variable b) Passing the variable as a parameter to the second function c) Either of the two methods in (A) and (B) d) binary stream

671


Is c is a procedural language?

603


Iam a B.Tech graduate and completed my engineering in 2009, from 2005 to 2009 and after that i had done nothing.Now i want to do job and get into BPO field . Friends give me suggestions as what to say in interview... if they ask me that what would you had done ... these many years without doing job ??????? pls urgent

1432


a sequence of bytes with one to one corrspondence to those in the external device a) sequential addressing b) address c) byte code d) none

727


Is stack a keyword in c?

640