-
Function problem
1) can anyone please help me to understand why this code just show 36 ? my analysis it should be :
1
4
9
16
25
Code:
#include<stdio.h>
int funct1(int count);
void main ()
{
int a,count;
for(count=1;count<=5;++ count);
{
a= funct1(count);
printf("a=%d\n",a);
}
}
int funct1(int x)
{
int y;
y=x*x;
return y ;
}
// 1 4 9 16 25
2) its difficult for me to understand argument exchange in the transfer function . a detail explanation will be really helpfull. thank you all for reading me.
Code:
/* The TOWERS OF HANOI- solver using recursion*/
#include<stdio.h>
void transfer (int n, char from, char to , char temp);
void main()
{
int n;
printf(" Welcome to the TOWERS OF HANOI\n\n");
printf("How many disks?");
scanf("%d", &n);
printf("\n");
transfer (n,'L','R','C');
}
void transfer ( int n, char from, char to, char temp)
{
if(n>0)
{
transfer(n-1,from,temp,to);
printf("Move disk %d from %c to %c\n",n, from,to);
transfer(n-1, temp,to,from);
}
return;
}
-
For the first:
Code:
for(count=1;count<=5;++ count);
For the second, I don't know what you're asking.
-
1st
for(count=1;count<=5;++count) ; is same as for(count=1;count<=5;++count){}
no semicolon required
2nd
find its explanation on Google.
-
tabstop @ thanks for your answer for the 1st problem . i got .
for the second function-
in the void transfer function , argument from ,to, temp receives - L,R, M respectively. then within the bracket -
Code:
{
transfer(n-1,from,temp,to);
printf("Move disk %d from %c to %c\n",n, from,to);
transfer(n-1, temp,to,from);
}
in the first transfer what will receive by from=
temp=
to=
and they will pass to void transfer function as well ?
And for 2nd transfer what will received by temp, to , from and what they will transfer to void transfer function as well ?
-
hr1212s @ hows it possible to find that in google?
-
-
lol its here as well ? thanks ...