Computer Science, asked by kaliaanshul123, 1 day ago

Program using switch statement to find factorial of natural, number


Answers

Answered by XxItzAdyashaxX
2

Answer:

include<stdio.h>

int main()

{

int number;

printf("Enter number\n");

scanf("%d",&number);

int choice;

printf("Enter 1 for summation or 2 for factorial\n");

scanf("%d",&choice);

int sum = 0;

int fact = 1;

switch(choice)

{

case 1:

while(number>0)

{

sum = sum+(number%10);

number = number/10;

}

printf("%d\n",sum);

break;

case 2:

while (number>0)

{

fact = fact*number;

number--;

}

printf("Factorial is %d\n",fact);

break;

default:

printf("Error\n");

}

return 0;

}

Similar questions