fact by elton


int maximum(int a,int b, int c, int d){


int max;
if(a>b) max=a;
if(b>a) max=b;

if(c>max) max=c;
if(d>max) max=d;
return max;
}

int main(int argc, char** argv) {

printf("%d",maximum(8,11,5,2));
//maximum();

return (EXIT_SUCCESS);
}
*/


/**
int samohlaska(char slovo[]){
int i=0,pocet=0;
while(slovo[i]!='\0') {
if(slovo[i]=='a'||slovo[i]=='e'||slovo[i]=='i'||slovo[i]=='o'||
slovo[i]=='u') {pocet++;}
i++;


}

return pocet;

}


int main(int argc, char** argv) {

char slov[]={"joyooino"};
printf("%d",samohlaska(slov));


return (EXIT_SUCCESS);
}

*/




/**
void fakt(int b){
int f=1;
while(b!=0){
f=f*b;
b--;
}
printf("%d\n",f);
}

int main(int argc, char** argv) {
// int b,a,c;


fakt(4);




return (EXIT_SUCCESS);

}
*/

/**
int faktorial(int a){
int b=1;
while(a!=0){
b=a*b;
a--;

}

return b;

}

int main(int argc, char** argv) {
int pole[10],pocet,i=0;
scanf("%d",& pocet);
while(i!=pocet){
printf("zadaj a");
scanf("%d",&pole[i]);
printf("%d",faktorial(pole[i]));

i++;
}


return (EXIT_SUCCESS);
}

*/
/**
void troj(int a,int b, int c){
if(c*c==a*a+b*b || a*a==c*c+b*b || b*b==a*a+c*c ) {printf("pravouhly");}
else printf(" nepravouhly");

}


int main(int argc, char** argv) {

troj(3,5,4);



return (EXIT_SUCCESS);


}

*/

/**
int prvocislo(int a){
int b=1;
while(b!=a){
if(a%b==0 && b!=1) {return 1;}

b++;

}
return 0;
}



int main(int argc, char** argv) {

printf("%d",prvocislo(8));



return (EXIT_SUCCESS);


}

*/



/**



int main(int argc, char** argv) {

int i=0;
char slovo[30];
printf("ake je tvoje meno?\n");
gets(slovo);
if(slovo[i]=='\0') {printf("neznas pisac ty papagaj?\n");return 1;}
while(slovo[i]!='\0'){
if (slovo[i]=='0'||slovo[i]=='1'||slovo[i]=='2'||slovo[i]=='3'||
slovo[i]=='4'||slovo[i]=='5'||slovo[i]=='6'||slovo[i]=='7'||slovo[i]=='8'||slovo[i]=='9'||slovo[i]==' ')
{printf("nepis mi tu cisla a nedavaj medzery");return 1;}
i++;}




slovo[0]=toupper(slovo[0]);
printf("no %s znas o tym ze si papagaj?\n",slovo);


return (EXIT_SUCCESS);


}

*/

/**
int main(int argc, char** argv) {
float celzius,farenhait,kelvin;
printf("zadaj teplotu v celziusoch");
scanf("%f",&celzius);
farenhait=9.0/5.0*celzius+32;
kelvin=celzius+273.15;
printf("%.2f v celyiusoch je %.2f vo farenhaitoch a %.2f v kelvinoch",celzius,farenhait,kelvin);




return (EXIT_SUCCESS);


}

*/


/**

int main(int argc, char** argv) {

int i=0,pocet;
printf("zadaj pocet hodnot");
scanf("%d",&pocet);
float celzius;
float rola[pocet];
float farenhait;
float kelvin;
while(i!=pocet){
printf("zadaj %d. teplotu v Celzius\n",i+1);
scanf("%f",&celzius);
rola[i]=celzius;
i++;
}

i=0;
while(i!=pocet){
farenhait=9.0/5.0*rola[i]+32;
kelvin=farenhait+273.15;
printf("%d: %.2f v celziusoch je %.2f vo farenhaitoch a %.2f v kelvinoch\n",i+1,rola[i],farenhait,kelvin);
i++;
}
return (EXIT_SUCCESS);


}

*/


/**

int main(int argc, char** argv) {
int i=0,pocet;
printf("zadaj pocet hodnot");
scanf("%d",&pocet);
float celzius;
float pole[pocet];
float far;
float kel;
while(i!=pocet){
printf("%d. hodnota v celzius",i+1);
scanf("%f",&celzius);
pole[i]=celzius;
i++;
}
i=0;
while(i!=pocet){
far=9.0/5.0*pole[i]+32;
kel=pole[i]+273.15;

printf("%d: %.2f v celziusoch je %.2f vo farenhajtoch a %.2f v kelvinoch\n",i+1,pole[i],far,kel);
i++;

}

return (EXIT_SUCCESS);

}

*/


/**
int slovo(char *veta){
char veta2[30];
int i=0,dlzka;
dlzka=strlen(veta);
while( veta[i]!='\0') {
veta2[i]=veta[dlzka-i-1];
i++;

}
veta2[i]='\0';
puts(veta2);
if( strcmp(veta,veta2)==0) {printf("je palyndrom");return 1;}
else printf("neni palyndrom");return 0;


}



int main(int argc, char** argv) {
char veta[30];
gets(veta);

slovo(veta);



return (EXIT_SUCCESS);


}

*/


/**
int slovo(char *veta){
char veta2[30];
char veta3[30];
int i=0,a=0,dlzka;

while(veta[i]!='\0'){
if(veta[i]==' ') {i++;}
veta3[a]=veta[i];
i++;
a++;
}

veta3[i]='\0';
printf("\nveta2 -%s\n",veta3);
// strcpy(veta,veta3);
dlzka=strlen(veta3);
i=0;
while( veta3[i]!='\0') {
veta2[i]=veta3[dlzka-i-1];
i++;

}
veta2[i]='\0';
printf("veta3 -%s\n",veta2);

if( strcmp(veta3,veta2)==0) {printf("je palyndrom");return 1;}
else printf("neni palyndrom");return 0;


}



int main(int argc, char** argv) {
char veta[30];
gets(veta);

slovo(veta);



return (EXIT_SUCCESS);


}

*/

/**
void zorad(int *pole, int pocet){
int i,j,pomoc;
for(i=0;i<pocet;i++){
for(j=0;j<pocet;j++){
if(pole[i]<pole[j]){
pomoc=pole[i];
pole[i]=pole[j];
pole[j]=pomoc;
}


}

}
i=0;
while(i!=pocet) {
printf(" %d ",pole[i]);
i++;
}



}

int main(int argc, char** argv) {
int i=0,pocet;
scanf("%d",&pocet);
int pole[pocet];
while(i!=pocet){
scanf("%d",&pole[i]);
i++;

}

i=0;
while(i!=pocet) {
printf(" %d ",pole[i]);
i++;
}
printf("\n");
zorad(pole,pocet);
return (EXIT_SUCCESS);


}

*/


char* abcd(char *pole, int pocet){
int i,j,pomoc;
for(i=0;i<pocet;i++){
for(j=0;j<pocet;j++){
if(pole[i]<pole[j]) {
pomoc=pole[i];
pole[i]=pole[j];
pole[j]=pomoc;
}
}
}
i=0;
while(i!=pocet){
printf(" %c",pole[i]);
i++;
}
return pole;
}

int main(int argc, char** argv) {
int i=0,pocet;
pocet=7;
char pole[pocet];
while(i!=pocet){

scanf("%c",&pole[i]);
i++;
}
i=0;
while(i!=pocet){

printf(" %c ",pole[i]);
i++;
}
char *smernik=abcd(pole,pocet);
i=0;
while(i!=pocet){
printf(" %c",pole[i]);
i++;
}
return (EXIT_SUCCESS);


}

/**
int shift,i;
scanf ("%d", &shift);
printf("Enter the string to encrypt: " );
char string[5];
scanf("%s", string);

char string2[5];
i = 0;
while(i <strlen(string)){
i++ ;
// strlen()je dlyka retazca)
string2[i] = (string[i] + shift);
}
string2[i]='\0'; // i je pozicia v stringu, na akej poyicii v retazci sa nachadzam
printf("%s\n",string2);




return (EXIT_SUCCESS);
}
*/
Last edited on
This code looks correct to me. Can you rephrase your question?

Actually one change I'd make is to have fakt() return a value also instead of printing it out. So I'd do this as:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
int fakt(int b){
    int f=1;
    while(b!=0){
        f=f*b;
        b--;
    }
    return f;
}

int faktorial(int n){
    if(n==1) return 1;
    return (n*faktorial(n-1));
}


int main(int argc, char** argv) {
  
    int a=4,vysle;
    print(a);
    printf ("zadaj cislo pre vzpocet faktorialu");
    scanf("%d",&a);
    vysle = fakt(a);
    printf("fakt(%d)=%d",a, vysle);
    vysle=faktorial(a);
     printf("vysledok je %d",vysle);
    return (EXIT_SUCCESS);
}
Topic archived. No new replies allowed.