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

Answers were Sorted based on User's Feedback



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

Answer / madhura musale

#include<stdio.h>
#include<conio.h>
void main()
{
int i,a[10],sum;
clrscr();
printf("\n Enter the elements in an array :");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("\n The sum of elements of an array are :");
for((i=0;i<10;i++)
sum=sum+a[i];
printf("\t %d",sum);
getch();
}

Is This Answer Correct ?    25 Yes 26 No

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

Answer / heemashree

#include "stdio.h"
#include "conio.h"
#include "stdafx.h"
void main()
{
int a[10];
int i,sum=0,n;

printf("enter number of elements");
scanf("%d",&n);



printf("Enter the array elements\n");
for (i=0; i<n; i++)
scanf("%d",&a[i]);

// sum of array elements
for (i=0; i<n; i++)
{
sum=sum+a[i];
}
printf("Sum of array elements===%d",sum);
}

Is This Answer Correct ?    0 Yes 1 No

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

Answer / bishmeet singh

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n,sum=0;
printf("enter the no. of elements");
back:
scanf("%d",&n);
if(n<10)
{
printf("elements sholud be less than 10\n enter again");
goto back;
}
printf("Enter %d elements",n);
for(i=0;i<n;i++)
{
scanf("%d",a[i]);
sum=sum+a[i];
}

printf("sum of your entered elements is %d",sum);
getch();
}

Is This Answer Correct ?    0 Yes 2 No

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

Answer / 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

More C Interview Questions

How can my program discover the complete pathname to the executable from which it was invoked?

0 Answers  


what do you mean by enumeration constant?

0 Answers  


What are compound statements?

0 Answers  


why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???

0 Answers  


Disadvantages of C language.

0 Answers   Impetus,






what is the use of bitfields & where do we use them?

2 Answers  


21. #define square(x) x*x main() { int i; i = 64/square(4); printf("%d",i); }

3 Answers  


What’s a signal? Explain what do I use signals for?

0 Answers  


What is the purpose of void pointer?

0 Answers  


How do you list a file’s date and time?

0 Answers  


how to write palindrome program?

3 Answers  


How can I remove the trailing spaces from a string?

0 Answers   Aspire,


Categories