Sunday, July 12, 2009

What is the C language for this?

Please help me form the C language for this program.. Thanks..





Create a program that allows entering of 5 letters. Then display the 4th letter four times, 3rd letter three times, 2nd two times and 1st once. -Is loop needed on this one? Will somebody give me the right codes for this.. If loop is needed please indicate it two ways..vertical and horizontal..

What is the C language for this?
In order for us to be able to HELP you do it, rather than DO IT FOR YOU, we need to know what you have so far.





(I'm pretty sure that 'it' should be replaced with 'your homework' in the sentence above.)
Reply:You might consider contacting a C expert at websites like http://getafreelnacer.com/
Reply:Is anyone looking looking for JAWS Scripting contract work? If so please let me know.





Thanks,


Wendy
Reply:I don't know what you mean by vertical and horizontal loops, but two loops (one embedded) are needed to print out each letter an "index-1" number of times. Array indices start at 0 in C, but we iterate through the array starting at 1.





Below is the code to a possible solution (indentation is not preserved):





#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;





int main(void)


{





int i, j;


char letter[5];





printf("Enter five letters: ");





scanf("%c %c %c %c %c", %26amp;letter[0], %26amp;letter[1], %26amp;letter[2], %26amp;letter[3], %26amp;letter[4]);








printf("Now print each character (index-1) number of times.\n");





for (i = 1; i %26lt;= 5; i++) {


for (j = 1; j %26lt;= i; j++) {


printf("%c ", letter[i-1]);


}


printf("\n");


}





return 0;





}





It was compiled using the following: gcc -o letters letters.c


You can copy/paste the above code into your editor. I'm assuming that you're using a Unix/Linux platform. The program prompts the user for five letters. Enter them separated with spaces.





Below is the output:





Enter five letters: f a c e s


Now print each character (index-1) number of times.


f


a a


c c c


e e e e


s s s s s


No comments:

Post a Comment