Δημοσιεύτηκε: 10 Οκτ 2011, 16:58
από Star_Light
Απλή υλοποίηση για τα πολλαπλάσια ενος αριθμου τον οποιο θα δινει ο χρήστης

Κώδικας: Επιλογή όλων
/*---------------------------------------------------
* 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>

void pollaplasia(int n);
void zuga_pollaplasia_perittou(int n);
int main() // main function

{
int n;

printf("Dwste to n: ");
scanf("%d",&n);

if((n%2)==1)
{
printf("H if doulevei");
zuga_pollaplasia_perittou(n);
}

else if((n%2)==0)
{
printf(" H else if doulevei");
pollaplasia(n);
} // function call

return 0;
}
//---------------------------------------------

void pollaplasia(int n)
{

int count , pollaplasia , s;

printf("\n Posa pollaplasia theleis na upologiseis? \n ");
scanf("%d",&s); // The limit is given by user

for(count=1; count<(s+1); count++) // for count=1 till ... s+1 because
// the zero is not included
{
pollaplasia=count*n;

printf("\n%d",pollaplasia);

}
return;
}

//---------------------------------------------
void zuga_pollaplasia_perittou(int n)
{
int s , count , pollaplasia;

printf("\n Posa pollaplasia theleis na upologiseis? \n ");
scanf("%d",&s);

for(count=1; count<(s+1); count++)
{
pollaplasia=count*n;
if((pollaplasia%2)==0)
printf("\n%d",pollaplasia);
}

return;
}



Το θέμα που προκύπτει ειναι αν τελικα θα πρέπει να χρησιμιποιήσω και δευτερη συνάρτηση η οποια απλα διαφοροποιείται με την βασικη(pollaplasia) μονο σε ενα if .