GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Placement Papers  >  Aztec Systems  >  C

 Print  |  
Question:  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 elments of even ones.




July 07, 2007 15:25:21 #1
 shah_saurabh164   Member Since: Visitor    Total Comments: N/A 

RE: A function even_odd_difference()passes the array o...
 
/* 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();

}
     

 

Back To Question