In: Computer Science
SWITCH CASE, WHILE, DO WHILE STRUCTURES Implement the following programs, attach a flow chart, and photos of its operation. 1. Read a number that represents the month and say what months it is. 2. Using the conditional "while" calculate the factorial of a number 3. Using the “do-while” conditional, make a program that prints all numbers from 1 up to a maximum number entered by the user.
PROGRAM 1:
#include <stdio.h>
int main()
{
int mon_num;
printf("Input Month No : ");
scanf("%d",&mon_num);
switch(mon_num)
{
case 1:
printf("January\n");
break;
case 2:
printf("February\n");
break;
case 3:
printf("March\n");
break;
case 4:
printf("April\n");
break;
case 5:
printf("May\n");
break;
case 6:
printf("June\n");
break;
case 7:
printf("July\n");
break;
case 8:
printf("August\n");
break;
case 9:
printf("September\n");
break;
case 10:
printf("October\n");
break;
case 11:
printf("November\n");
break;
case 12:
printf("December\n");
break;
default:
printf("invalid Month number. \nPlease try again ....\n");
break;
}
return 0;
}
OUTPUT:
FLOWCHART:
PROGRAM 2:
#include <iostream>
using namespace std;
int main() {
int num;
cout<<"\n ENTER A NUMBER:";
cin>>num;
int fact = 1;
while(num>1)
{
fact=fact*num;
num--;
}
cout<<"\nFACTORIAL = "<<fact;
return 0;
}
OUTPUT:
FLOWCHART:
PROGRAM 3:
#include <iostream>
using namespace std;
int main() {
int n;
cout<<"\nEnter how many numbers you want to enter:";
cin>>n;
int arr[n];
int max = -99999;
int i = 0;
do{
cout<<"\nENTER NUMBER "<<i+1<<" :";
cin>>arr[i];
if(arr[i] > max)
{
max=arr[i];
}
i++;
}while(i!=n);
cout<<"\nLarger numbber = "<<max;;
return 0;
}
OUTPUT:
FLOWCHART
DON'T FORGET TO GIVE A LIKE