Integer To Character in C
Q. Write a C program to convert Number in Character?
#include <stdio.h>
#include <conio.h>
void main()
{
int n, sum = 0;
clrscr();
printf("Enter the number to print in words: ");
scanf("%d", &n);
while(n > 0)
{
sum = (sum * 10) + (n % 10);
n = n /10;
}
while(sum > 0)
{
switch(sum % 10)
{
case 0:
printf("Zero ");
break;
case 1:
printf("One ");
break;
case 2:
printf("Two ");
break;
case 3:
printf("Three ");
break;
case 4:
printf("Four ");
break;
case 5:
printf("Five ");
break;
case 6:
printf("Six ");
break;
case 7:
printf("Seven ");
break;
case 8:
printf("Eight ");
break;
case 9:
printf("Nine ");
break;
}
sum = sum / 10;
}
}
Q. Write an algorithm to convert Number in Character?
1. Start 2. Initialize an integer variable `sum` as 0. 3. Prompt the user to enter a number `n`. 4. Read the input number `n`. 5. Reverse the number `n`: - While `n > 0`: - Extract the last digit of `n` using `digit = n % 10`. - Update `sum = sum * 10 + digit`. - Remove the last digit from `n` by `n = n / 10`. 6. Print each digit of the reversed number `sum` in words: - While `sum > 0`: - Extract the last digit of `sum` using `digit = sum % 10`. - Use a `switch` or `if-else` construct to print the word corresponding to `digit`: - 0 → "Zero" - 1 → "One" - 2 → "Two" - 3 → "Three" - 4 → "Four" - 5 → "Five" - 6 → "Six" - 7 → "Seven" - 8 → "Eight" - 9 → "Nine" - Remove the last digit from `sum` by `sum = sum / 10`. 7. End
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com