From vasanth

V

vasanthvn

The first exercise of mine:/* Write a C-program to print the vaue of
the alphabet when an integet value is entered .. For example if 1 is
entered then A must be printed on the screen,if 2 is printed then B
must be printed...like this so on......*/
 
E

Eric Sosman

The first exercise of mine:/* Write a C-program to print the vaue of
the alphabet when an integet value is entered .. For example if 1 is
entered then A must be printed on the screen,if 2 is printed then B
must be printed...like this so on......*/

Do you have a question?
 
M

Mike Wahler

The first exercise of mine:/* Write a C-program to print the vaue of
the alphabet when an integet value is entered .. For example if 1 is
entered then A must be printed on the screen,if 2 is printed then B
must be printed...like this so on......*/

Hints:

const char array[] = "Hello";

printf("%c\n", array[0]);
printf("%c\n", array[1]);

printf("%d\n", 0 + 1);

-Mike
 
S

santosh

The first exercise of mine:/* Write a C-program to print the vaue of
the alphabet when an integet value is entered .. For example if 1 is
entered then A must be printed on the screen,if 2 is printed then B
must be printed...like this so on......*/

What a dumb exercise. You need to throw away the material from which
you got that exercise and buy a good C text like K&R2.
 
D

Default User

santosh said:
What a dumb exercise. You need to throw away the material from which
you got that exercise and buy a good C text like K&R2.


Most newbie exercises are fairly dumb. I don't see any particular
objection to this one.




Brian
 
P

pete

The first exercise of mine:/* Write a C-program to print the vaue of
the alphabet when an integet value is entered .. For example if 1 is
entered then A must be printed on the screen,if 2 is printed then B
must be printed...like this so on......*/

/* BEGIN new.c */

#include <stdio.h>

int main(void)
{
int integet_value, rc;

puts("Enter an integer from 1 to 26.");
rc = scanf("%d", &integet_value);
while (rc == 1 && integet_value > 0 && 27 > integet_value) {
printf("The number %d letter of the alphabet is %c.\n\n",
integet_value,
" ABCDEFGHIJKLMNOPQRSTUVWYXYZ"[integet_value]);
puts("Enter an integer from 1 to 26 to continue\n"
"or any other integer to quit.");
rc = scanf("%d", &integet_value);
}
return 0;
}

/* END new.c */
 
M

Malcolm McLean

Default User said:
Most newbie exercises are fairly dumb. I don't see any particular
objection to this one.
It tempts the newbie to assume that the character encoding is in
alphabetical order.
 
C

CBFalconer

Malcolm said:
It tempts the newbie to assume that the character encoding is in
alphabetical order.

On the contrary, it demonstrates how to avoid such (erroneous)
assumptions.
 
E

Eric Sosman

Malcolm said:
It tempts the newbie to assume that the character encoding is in
alphabetical order.

... and offers an learning opportunity in overturning the
tempting assumption.

Temptation need not be a bad thing; read "The Man That
Corrupted Hadleyburg."
 
D

Default User

Malcolm said:
of >>> the alphabet when an integet value is entered .. For example
if 1 is >>> entered then A must be printed on the screen,if 2 is
printed then B >>> must be printed...like this so on......*/
It tempts the newbie to assume that the character encoding is in
alphabetical order.

I don't see how. There is such a thing as alphabetical order, and
mapping that to integers seems natural. It doesn't say anything about
the order of alpha characters in the particular character encoding used.

If the student solved the problem in a way that used ASCII or
something, then they should be marked down for a non-portable solution.
There is a fairly straight-forward method that achieves it portably.




Brian
 
A

August Karlstrom

pete skrev:
/* BEGIN new.c */

#include <stdio.h>

int main(void)
{
int integet_value, rc;

puts("Enter an integer from 1 to 26.");

You probably mean: "Enter an integet...".
rc = scanf("%d", &integet_value);
while (rc == 1 && integet_value > 0 && 27 > integet_value) {
printf("The number %d letter of the alphabet is %c.\n\n",
integet_value,
" ABCDEFGHIJKLMNOPQRSTUVWYXYZ"[integet_value]);
puts("Enter an integer from 1 to 26 to continue\n"
"or any other integer to quit.");
rc = scanf("%d", &integet_value);
}
return 0;
}

/* END new.c */


August
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top