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

Program 4 \"Sum The Digits In An Integer\" -------------------------------------

ID: 668137 • Letter: P

Question

Program 4 "Sum The Digits In An Integer"

-----------------------------------------------------------------------------------------------------------------------------------------------------

Write a program that reads an integer between 0 and 999 (inclusive) and sums the digits in the integer.

For example, if the integer is 932, the sum of all the digits is 14.

Your program output should look like this:

------------------------------------------------------------------------------------

------------------------------------------------------------------------------------

Explanation / Answer

Using switch case i have solveing these process ,so

Program :

#include<stdio.h>

#include<math.h>

#include<conio.h>

int main(void)

{

    while(1)

{

      printf("Enter a number between 1-999 (enter 0 to exit): ");

      scanf("%d", &number);

      if (number==0)

        break;

      if (number > 999 || number < 1)

     continue

      a=number/100;

      b=number/10;

      switch(a)

      {

                case 1:

                     printf("One Hundred");

                     break;

                case 2:

                     printf("Two Hundred");

                     break;

                case 3:

                     printf("Three Hundred");

                     break;

                case 4:

                     printf("Four Hundred");

                     break;

                case 5:

                     printf("Five Hundred");

                     break;

                case 6:

                     printf("Six Hundred");

                     break;

                case 7:

                     printf("Seven Hundred");

                     break;

                case 8:

                     printf("Eight Hundred");

                     break;

                case 9:

                     printf("Nine Hundred");

                     break;

       switch(b)

{

                case 1:

                     printf("Ten");

                     break;

                case 2:

                     printf("Twenty");

                     break;

                case 3:

                     printf("Thirty");

                     break;

                case 4:

                     printf("Forty");

                     break;

                case 5:

                     printf("Fifty");

                     break;

                case 6:

                     printf("Sixty");

                     break;

                case 7:

                     printf("Seventy");

                     break;

                case 8:

                     printf("Eighty");

                     break;

                case 9:

                     printf("Ninety");

                 break;

                     return 0;

                     }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote