Δημοσιεύτηκε: 11 Οκτ 2011, 14:13
από migf1
migf1 έγραψε:
Στο ότι δε αναφέρεται στην εκφώνηση πως στην περίπτωση των περιττών το πλήθος των πολλαπλασίων που βάζει ο χρήστης αναφέρεται στα συνολικά πολλαπλάσια, άρα είναι το ταβάνι και για τα ζυγά πολλαπλάσιά του. Έτσι όπως είναι γραμμένη, περίμενα να μου βγάλει τα 3 πρώτα ζυγά πολλαπλάσια του 9 (18, 36, 54)


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

/*---------------------------------------------------
* Upologizei ta pollaplasia enos arithmou
* orio sta pollaplasia pou upologizei to opoio
* epilegei o xristis , epiprostheta otan
* o arithmos pou 8a epilegetai gia na upologis8oun
* ta pollaplasia tou tha einai perittos arithmos
* tote tha ektupwnonte mono ta zuga tou pollaplasia
*
* version : 1.2 by Kostas
*--------------------------------------------------- */

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

// Constants

#define MAXINBUF 255+1

// Function Prototypes

void pollaplasia( const int /*num*/, const int /*nmuls*/ );
void zuga_pollaplasia_perittou( const int /*num*/, const int /*nmuls*/ );

// --------------------------------------------------------------------------------
int main( void ) // main function
{
char inbuf[ MAXINBUF ] = {'\0'};
int num = 0, nmuls = 0;

printf("Dwste arithmo: ");
fgets(inbuf, MAXINBUF, stdin);
num = atoi( inbuf );

printf("Posa pollaplasia na ypologistoyn; ");
fgets(inbuf, MAXINBUF, stdin); // the limit is given by user
nmuls = atoi( inbuf );

if ( num % 2 == 0 ) // num is even number
pollaplasia( num, nmuls );
else // num is odd number
zuga_pollaplasia_perittou( num, nmuls );

return 0;
}
// --------------------------------------------------------------------------------
void pollaplasia( const int num, const int nmuls )
{
int i=0, mul=0;

for (i=1; i < nmuls + 1; i++) // for count=1 till ... n+1 because
{ // the zero is not included
mul = i * num;
printf("%d ", mul);
}
putchar('\n');

return;
}
// --------------------------------------------------------------------------------
void zuga_pollaplasia_perittou( const int num, const int nmuls )
{
int i=0, j=0, mul=0;

printf("\nTa %d prwta zyga pollaplasia toy %d\n--------------------------------------------\n", nmuls, num);
for (i=1, j=0; j < nmuls; i++)
{
mul = i * num;
if ( mul % 2 == 0 ) {
printf("%d ", mul);
j++;
}
}
putchar('\n');

return;
}