Computer Science, asked by pratapabir27691, 10 months ago

How to find the factorial of a number using switch statement Factors of the given number

Answers

Answered by mayanksharma789594
9

Answer:

Explanation:

#include<stdio.h>

#include<conio.h>

void main()

{

   int number;

   clrscr();

   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");

   }

  getch();

}

Similar questions