Solved

Listing letters...

Posted on 2000-03-09
4
206 Views
Last Modified: 2010-04-15

ok... i want to make a program that lists chars to the screen in this order:
a,b,c,d, and so on until it comes to z... then it shall start at aa and move upwards like this: aa, ab, ac...

how do i do this ?
0
Comment
Question by:GrApZ2
  • 3
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 2602718
This can easily be done using nested loops (as I assume you'd also like 'ba bb bc' ;-)

#include <stdio.h>

void main ( void)
{
char c1, c2;

for ( c1 = 'a'; c1 <= 'z'; c1++)
{
 printf ( "%c", c1);
}

printf ( "\n");

for ( c1 = 'a'; c1 <= 'z'; c1++)
{
  for ( c2 = 'a'; c2 <= 'z'; c2++)
  {
   printf ( "%c%c", c1, c2);
  }
}
}
0
 
LVL 86

Expert Comment

by:jkr
ID: 2602726
A little correction to 'beautify'  the output:

#include <stdio.h>

void main ( void)
{
char c1, c2;

for ( c1 = 'a'; c1 <= 'z'; c1++)
{
 printf ( "%c", c1);
}

printf ( "\n");

for ( c1 = 'a'; c1 <= 'z'; c1++)
{
  for ( c2 = 'a'; c2 <= 'z'; c2++)
  {
   printf ( "%c%c ", c1, c2);  /* note the space */
  }
 printf ( "\n");  /* a line feed when we start with a new 1st letter */
}
}

It's hard to elaborate that, as I think it's self-explaining, but please ask if you encounter problems or need more information...
0
 

Author Comment

by:GrApZ2
ID: 2602763
but... ok... how do i include captial letters and numbers... and make it countinue forever (at least almost)
0
 
LVL 86

Expert Comment

by:jkr
ID: 2605705
Hmm, capital letter is quite easy, just use

for ( c1 = 'A'; c1 <= 'Z'; c1++)
{
  for ( c2 = 'A'; c2 <= 'Z'; c2++)
  {
   printf ( "%c%c ", c1, c2);  /* note the space */
  }
 printf ( "\n");  /* a line feed when we start with a new 1st letter */
}

instead... how would you like to use the numbers?
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SCANF - LIMIT THE NUMBER OF CHARARACTERS 1 63
sameEnds challenge 3 161
Test the speeds on my PC Drives 12 48
If a cell in a range equals "YES" return specific Test. 4 33
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question