how to get the sum of each element of an array. There are two function in this given example one for reading the array element and other for writing on console.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
void read(int *,int);
void display(int *,int);
int a[5],i,sum=0;
clrscr();
printf("Enter five elements for an array \n");
read(a,5);
printf("The list elements are \n");
display(a,5);
for(i=0;i<5;i++)
{
sum+=a[i];
}
printf("The sum of the elements of the array is %d\n",sum);
getch();
}
void read(int c[],int i)
{
int j;
for(j=0;j<i;j++)
scanf("%d",&c[j]);
fflush(stdin);
}
void display(int d[],int i)
{
int j;
for(j=0;j<i;j++)
printf("%d ",d[j]);
printf("\n");
}
Output:
Previous - Array Implementation in C
Data Structure Tutorial
1. Introduction to Data Structures
2. Pointer in C
3. Pointer and Structure in C
4. Linear and Non-Linear Data Structure in C
5. Array Implementation in C
6. Sum of array element in C
7. Addition of two arrays element in C
8. Inverse of an array in C
9. Merge of two arrays in C
10.Overview of Linked List
11.Singly Linked List
12.Doubly Linked List
13.Circular Linked List
14.Count number of nodes
15.Split a list into two equal size list
16.Merge two list into a single list
17.Stack
18.Push and Pop operation of stack.
19.Push and Pop operation of stack using linked list.
20.Queue implementation using array.
21.Queue implementation using linked list.
22.Circular queue implementation using array.
23.Tree data structure
24.Representing Graph using adjacency list & perform DFS & BFS
0 comments:
Speak up your mind
Tell us what you're thinking... !