-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram131.c
More file actions
52 lines (40 loc) · 928 Bytes
/
Copy pathprogram131.c
File metadata and controls
52 lines (40 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<stdio.h>
#include<stdlib.h>
int SumOdd(int Arr[],int iSize)
{
int iCnt = 0;
int iSum = 0;
for(iCnt = 0 ; iCnt < iSize; iCnt++)
{
if((Arr[iCnt] % 2) != 0)
{
iSum = iSum + Arr[iCnt];
}
}
return iSum;
}
int main()
{
int iLength = 0,iCnt =0, iRet = 0;
int *ptr = NULL;
printf("Enter the Number of the Element :\n");
scanf("%d",&iLength);
// Step 1: Allocate the memory
ptr = (int *)malloc(iLength * sizeof(int));
if(ptr == NULL)
{
printf("Unable to allocate memory");
return -1;
}
printf("Enter the element:\n");
for(iCnt = 0; iCnt < iLength; iCnt++)
{
scanf("%d",&ptr[iCnt]);
}
// Step 2: Use the memory
iRet = SumOdd(ptr,iLength);
printf("Summation of Odd Element are :%d\n",iRet);
// Step 3: Free the memory
free(ptr);
return 0;
}