Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Ask the user to enter a digit between 0 and 9. Have the program print out the

ID: 665486 • Letter: 1

Question

1. Ask the user to enter a digit between 0 and 9. Have the program print out the digit in words, for example:

Enter a digit between 0 and 9: 4

You entered the number four

Assume that the user will enter only a single digit. The user may accidentally enter a single character, and this should generate an error message

2.

Ask for a single character to be typed from the keyboard. Analyze the character and print out a message that it is:

an alphabetic character (a-z or A-Z)

a digit (0-9) or

a special character (anything else)

Explanation / Answer

1.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
cout<<“Enter a digit between 0 and 9:”;
cin>>n;
switch(n)
{
case 1: cout<<“You entered the number One”;
break;
case 2: cout<<“You entered the number Two”;
break;
case 3: cout<<“You entered the number Three”;
break;
case 4: cout<<“You entered the number Four”;
break;
case 5: cout<<“You entered the number Five”;
break;
case 6: cout<<“You entered the number Six”;
break;
case 7: cout<<“You entered the number Seven”;
break;
case 8: cout<<“You entered the number Eight”;
break;
case 9: cout<<“You entered the number Nine”;
break;
else: cout<<"Wrong Input";
break;
}
getch();
}

2.

#include<stdio.h>
#include<conio.h>
void main()
{
    char ch;
    clrscr();
    printf(“Enter a single character:”);
    scanf(“%c”,&ch);

    if((ch>=’A’&&ch<=’Z’)||(ch>=’a’&&ch<=’z’))
        printf(“nYou have entered an alphabet”);
    else if(ch>=’0’&&ch<=’9)
        printf(“You have entered a digit”);
     else
        printf(“You have entered a special character”);

    getch();
}