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

20. main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); } Answer:??????

2 Answers  


dibakar & vekatesh..uttejana here..abt ur reply for in place reversal of linked list..wats p stands for there?

1 Answers  


Diff: between this 2 classes in terms of memory class A { int i; char c; double d; }; class A { double d; int i; char c; }; How it is calculating?

1 Answers   HCL,


On most computers additional memory that is accessed through an adapter of feature card along with a device driver program. a) user memory b) conventional memory c) expandedmemory d) area

0 Answers  


can we declare a variable in different scopes with different data types? answer in detail

3 Answers   TCS,






How to find a missed value, if you want to store 100 values in a 99 sized array?

0 Answers   Honeywell, Zomato,


What are local variables c?

0 Answers  


palindrome for strings and numbers----Can anybody do the prog?

6 Answers   CTS, TCS, Vipro Lifescience Pvt,


Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?

0 Answers  


What is sizeof array in c?

0 Answers  


code for replace tabs with equivalent number of blanks

0 Answers   Bosch,


I need to take a sentence from input and sort the words alphabetically using the C programming language. Note: This is C not C++. qsort and strtok not allowed

4 Answers   Aspire,


Categories