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

Answer Posted / mathews m

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,sum=0,x[20];
clrscr();
printf("enter the array space");
scanf("%d",&n);
printf("enter the elements");
for(i=0;i<n;i++)
scanf("%d"&x[i]);
for(i=0;i<n;i++)
{
sum=sum+x[i];
}
printf("the sum of elements in an array=%d");
}
getch();

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can I delete a file?

630


I need testPalindrome and removeSpace #include #define SIZE 256 /* function prototype */ /* test if the chars in the range of [left, right] of array is a palindrome */ int testPalindrome( char array[], int left, int right ); /* remove the space in the src array and copy it over to the "copy" array */ /* set the number of chars in the "copy" array to the location that cnt points t */ void removeSpace(char src[], char copy[], int *cnt); int main( void ) { char c; /* temporarily holds keyboard input */ char string[ SIZE ]; /* original string */ char copy[ SIZE ]; /* copy of string without spaces */ int count = 0; /* length of string */ int copyCount; /* length of copy */ printf( "Enter a sentence:\n" ); /* get sentence to test from user */ while ( ( c = getchar() ) != '\n' && count < SIZE ) { string[ count++ ] = c; } /* end while */ string[ count ] = '\0'; /* terminate string */ /* make a copy of string without spaces */ removeSpace(string, copy, ©Count); /* print whether or not the sentence is a palindrome */ if ( testPalindrome( copy, 0, copyCount - 1 ) ) { printf( "\"%s\" is a palindrome\n", string ); } /* end if */ else { printf( "\"%s\" is not a palindrome\n", string ); } /* end else */ return 0; /* indicate successful termination */ } /* end main */ void removeSpace(char src[], char copy[], int *cnt) { } int testPalindrome( char array[], int left, int right ) { }

2214


Difference between macros and inline functions? Can a function be forced as inline?

712


How to declare pointer variables?

686


Explain the difference between malloc() and calloc() function?

602






In c programming language, how many parameters can be passed to a function ?

631


Find duplicates in a file containing 6 digit number (like uid) in O (n) time.

2609


Can you mix old-style and new-style function syntax?

664


What is realloc in c?

581


What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?

589


Why does notstrcat(string, "!");Work?

643


How is a null pointer different from a dangling pointer?

557


Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?

759


Explain what is the advantage of a random access file?

666


What is the purpose of sprintf() function?

602