#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    74
    Rep Power
    2

    Displaying problem


    Code:
    #include <stdio.h>
    #include <conio.h>
    
    main()
    {
    	char x, y;
    	
    	for(x='a'; x<='z'; x++)
    	{
    		printf("%c", x);
    	}
    	printf("\n");
    	for(y='z'; y<='a'; y--)
    	{
    		printf("%c", y);
    	}
    	getch();
    }
    output
    Code:
    abcdefghijklmopqrstuvwxyz
    target output
    Code:
    abcdefghijklmnopqrstuvwxyz
    zywvutsrqponmlkjihfgedcba
    i dont see any problem with the lower loop, but why is it not displayed when i run the program?

    and is it possible to output the target output with only one loop? how?

    i tried this
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    main()
    {
    	char x, y;
    	
    	for(x='a', y='z'; x<='z'; x++, y--)
    	{
    		printf("%c\n%c", x, y);
    	}
    	getch();
    }
    but i did not get my target output. help please -_- still learning
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    The lower loop, meant to display the alphabet backwards, was written thus:
    for(y='z'; y<='a'; y--)

    The way that a for-loop works is that in order to continue looping, the condition expression, the one in red, needs to evaluate to true. Once it evaluates to false, you drop out of the loop. And if it evaluates to false from the very beginning, then you never ever execute the loop.

    Is that expression, 'z'<='a', true or false?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    74
    Rep Power
    2
    Originally Posted by dwise1_aol
    The lower loop, meant to display the alphabet backwards, was written thus:
    for(y='z'; y<='a'; y--)

    The way that a for-loop works is that in order to continue looping, the condition expression, the one in red, needs to evaluate to true. Once it evaluates to false, you drop out of the loop. And if it evaluates to false from the very beginning, then you never ever execute the loop.

    Is that expression, 'z'<='a', true or false?
    Thank you =)

IMN logo majestic logo threadwatch logo seochat tools logo