Solved

Listing letters...

Posted on 2000-03-09
4
207 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

860 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