Solved

Listing letters...

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
posix semaphore deadlock 13 114
Describe order of operation while copying text 11 115
valid enum? 6 73
Digital Output does not have continuity to ground? 3 84
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…
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 and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

895 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

15 Experts available now in Live!

Get 1:1 Help Now