Write a program to calculate the difference of the two sums ?

A function even_odd_difference()passes the array of elements.Write a program to calculate the difference of the two sums of which one sum adds the elements of odd ones and another adds the elements of even ones.
This question is related to Aztec-Systems Interview

Showing Answers 1 - 3 of 3 Answers

shah_saurabh164

  • Jul 23rd, 2007
 

/* Saurabh Shah - PUNE*/

#include<stdio.h>
#include<conio.h>

void main()
{
    int arr[30],i,n,sum1=0,sum2=0,sum;
    clrscr();
    printf("how many numbers u want ? :");
    scanf("%d",&n);
    printf("nEnter the %d numbers...:n",n);
    for(i=0;i<n;i++)
        scanf("%d",&arr[i]);
    for(i=0;i<n;i++)
    {
        if(i%2 == 0)
            sum1 += arr[i];
        else
            sum2 += arr[i];
    }
    printf("n Even sum = %dn Odd sum = %d",sum1,sum2);
    sum=sum1-sum2;
    printf("n Difference = %d",sum);

    getch();

}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions