write a menu driven C program using switch case to find sum of the digits of number
Answers
Answered by
8
#include <stdio.h>
#include <conio.h>
void main()
{
int num,temp,sum=0,rem,i,choice;
clrscr();
printf(“\nEnter the number “);
scanf(“%d”,&num);
printf(“\n****************************”);
printf(“\n* 1. Sum of the digits *”);
printf(“\n* 2. Exit *”);
printf(“\n****************************”);
do
{
printf(“\n\nEnter choice =>”);
scanf(“%d”,&choice);
switch (choice)
{
case 1:
temp=num;
do
{
rem=temp%10;
sum=sum+rem;
temp=temp/10;
}
while(temp!=0);
printf(“\nSum of digits of %d is =%d”,num,sum);
break;
case 2:
exit();
default: printf(“\nChoice is wrong!!!”);
}
}
while(choice<=2);
getch();
}
#include <conio.h>
void main()
{
int num,temp,sum=0,rem,i,choice;
clrscr();
printf(“\nEnter the number “);
scanf(“%d”,&num);
printf(“\n****************************”);
printf(“\n* 1. Sum of the digits *”);
printf(“\n* 2. Exit *”);
printf(“\n****************************”);
do
{
printf(“\n\nEnter choice =>”);
scanf(“%d”,&choice);
switch (choice)
{
case 1:
temp=num;
do
{
rem=temp%10;
sum=sum+rem;
temp=temp/10;
}
while(temp!=0);
printf(“\nSum of digits of %d is =%d”,num,sum);
break;
case 2:
exit();
default: printf(“\nChoice is wrong!!!”);
}
}
while(choice<=2);
getch();
}
nandhinimouli:
click on thankyou if u find it useful
Similar questions