Thread: Function problem

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    73

    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;
    	 
    	 }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    For the first:
    Code:
    for(count=1;count<=5;++ count);
    For the second, I don't know what you're asking.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    18
    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.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    73
    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 ?

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    73
    hr1212s @ hows it possible to find that in google?

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    18

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    73
    lol its here as well ? thanks ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tough problem with function pointers
    By Montejo in forum C Programming
    Replies: 10
    Last Post: 12-22-2009, 01:17 AM
  2. wxWidgets link problem
    By cboard_member in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2006, 02:36 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM