Δημοσιεύτηκε: 09 Σεπ 2011, 23:05
από migf1
Ούτε καν πίνακες δεν θέλει :)

Κώδικας: Επιλογή όλων

#include <stdio.h>
#include <stdlib.h>

#define MAXINBUF 254+1

#define ISEVEN(n) ( (n) % 2 == 0 )

// ---------------------------------------------------------------------------------
int main( void )
{
char inbuf[ MAXINBUF ] = { 0 };
int count5 = 0, low =0, high = 0, sum = 0, sum5 = 0;

printf("Κάτω όριο: ");
fgets(inbuf, MAXINBUF, stdin);
low = atoi( inbuf );

printf("Άνω όριο : ");
fgets(inbuf, MAXINBUF, stdin);
high = atoi( inbuf );

if (low > high ) {
int temp = low;
low = high;
high = temp;
}

for (count5=0; low < high+1; low++)
{
if ( ISEVEN(low) ) {
sum += low;
sum5 += low;
printf("%d + ", low);
count5++;
}
if ( count5 == 5 || low == high ) {
printf("\b\b= %d\n", sum5);
count5 = sum5 = 0;
}
}

printf("\nΆθροισμα: %d\n\n", sum);

return 0;
}

και δουλεύει και με πλήθη άρτιων που δεν διαιρούνται με το 5 :)