Get Answers to all your Questions

header-bg qa

Write a menu driven C program using switch case to find sum of the digits of number

Answers (1)

best_answer

#include <stdio.h>
#include <conio.h>
void main()

int num,temp,sum=0,rem,i,choice;
clrscr();
printf(“ Enter the number “); 
scanf(“0”,&num);
printf(“ ****************************”);
printf(“ * 1. Sum of the digits     *”);
printf(“ * 2. Exit                  *”);
printf(“ ****************************”);
do

   printf(“ Enter choice =>”);
   scanf(“0”,&choice);
  switch (choice)
   
       case 1:  
       temp=num;
       do
         
              rem=temp%10;
              sum=sum+rem;
              temp=temp/10;
          
         while(temp!=0);     
         printf(“ Sum of digits of 0 is =0”,num,sum);  
         break;  
 case 2:
      exit();
 
default:    printf(“ Choice is wrong!!!”);

 
while(choice<=2);  
getch();
 

Posted by

Deependra Verma

View full answer