Computer Science, asked by Mamtakant, 3 months ago

Write a menu driven program to accept a number of user's choice and print the statement's as per choices and write default statement to print invalid choice. 1. Print the sum of first ten natural numbers. 2. Print the product of first ten natural numbers.​

Answers

Answered by rounakjaiswal49
1

Explanation:

Write a menu driven C program using switch-case to find: (a) Sum of the digits of number (b) Factorial of N.

Prashant Kumar , ifim college,Bengalore

Answers

#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