-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram9_1.c
88 lines (66 loc) · 1.54 KB
/
program9_1.c
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
///aceept N numbers from user and return difference betwweem summation of
//even elements and summation of odd elements
#include<stdio.h>
#include<stdlib.h>
int Difference(int Arr[] ,int iLength)
{
int iCnt = 0;
int iEvenSum=0;
int iOddSum=0;
int iDiff=0;
for(iCnt = 0;iCnt<=iLength;iCnt++);
{
if((Arr[iCnt] % 2)==0)
{
iEvenSum=iEvenSum+Arr[iCnt];
}
else
{
iOddSum=iOddSum+Arr[iCnt];
}
iDiff=iEvenSum - iOddSum;
}
return iDiff;
}/*
int main()
{
int iSize = 0,iRet= 0,iCnt=0,iLength;
int *p=NULL;
printf("enter number of elements ");
scanf("%d",&iSize);
p=(int *)malloc(iSize * sizeof(int));
if(p== NULL)
{
printf("unable to allocate memory");
return -1;
}
for(iCnt = 0;iLength;iCnt++)
{
printf("enter elements : %d",iCnt);
scanf("%d",&p[iCnt]);
}
iRet=Difference(p,iSize);
printf("REsult is %d",iRet);
free(p);
return 0;
}
*/
int main()
{
int iSize = 0;
int *ptr = NULL;
int iCnt = 0;
int iRet = 0;
printf("enter number of elements : \n");
scanf("%d",&iSize);
ptr =(int *)malloc(iSize * sizeof(int));
printf("enter the elemnts : \n");
for(iCnt = 0; iCnt < iSize; iCnt++)
{
scanf("%d",&ptr[iCnt]);
}
iRet=Difference(ptr,iSize);
printf("result is %d",iRet);
free(ptr);
return 0;
}