Solved

Listing letters...

Posted on 2000-03-09
4
199 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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 how to create, access, and change arrays in the C programming language.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now