Write a program which allows the entrance of 10 integers and which calculates the difference between the sum of the even elements and the sum of the Odd elements.
for example : 1 6 7 4 5 3 1 8 2 5
==> (6+4+8+2) - (1+7+5+3+5+1) = -2
******** In Algorithm ********
Algorithm Variables i,tab[6],sum: integers Begin sum ← 0 for i from 1 to 6 write(" Enter an integer :") read(tab[i]) if( tab[i] % 2 = 0 ) then sum ← sum + tab[i] else sum ← sum - tab[i] next_if next_for write(" the difference equal to ",sum) End Résultat ==> 8 5 7 0 2 1 the difference equal to -3
******** In language C ********
#include <stdio.h> #include <conio.h> int main() { int sum ,i ,tab[10]; sum = 0; for(i=0;i < 10;i++){ printf(" Enter an integer :"); scanf("%d",&tab[i]); if( tab[i] % 2 == 0 ) sum = sum + tab[i]; else sum = sum - tab[i]; } printf("the difference equal to %d ",sum); return 0; }
******** In C++ ********