Professional Documents
Culture Documents
Document
Document
*/
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <math.h>
int getUserInput(char message[], char datatype[5]); // get the user input and check if it's valid.
void removeBuffer();// Clear the buffer so scanf can ask the user again.
// MAIN
int main(){
int menuInput;
while(menuInput != 4){// This will loop forever until user input number 4.
clrscr();
menuInput = menu();
mainOption(menuInput);
// MENU SETTINGS
int mainOption(int input){
switch(input){
case 1: introductionC();break;
case 2: subOptionStructure();break;
case 3: displayAuthorLife();break;
int menu(){
/*
*/
display();
void display(){
/*
*/
printf("\n"
"1. C LANGUAGE INTRODUCTION\n"
"\tD. Array\n"
"\tE. Recursor\n"
"4. Quit\n\n"
);
void introductionC(){
/*
*/
"Origins at Bell Labs:\n\t* C was created by Dennis Ritchie at Bell Labs (AT&T) in the
early 1970.\n\t*It evolved from an earlier programming language called B, which was developed by Ken
Thompson.B, in turn, had its \n\troots in BCPL (Basic Combined Programming Language).",
};
int user_choice;
clrscr();
if(user_choice == 1){
break;
void displayAuthorLife(){
"Hello my name is Louel Eturalde the author of this program.\nI was born on November
27, 2003 at Bagong silang Caloocan City.",
"My hobbies are playing mobile games, eating, and also I love music.\nI have 7 siblings,
My favourite color is marine color and my favourite sports is basketball.\nI like sweets food. ",
"Im currently studying at Bestlink college of the philippines, and they have the best
teachers I love they all."
};
int user_choice;
clrscr();
if(user_choice == 1){
break;
char subUserInput;
int alive = 1;
while(alive != 0){
clrscr();
"\tD. Array\n"
"\tE. Recursion\n"
switch(toupper(subUserInput)){
void rescursionProgram(){
int menuOption = getUserInput("Choose sequential program example from the menu[1-4]: ",
"%d");
switch(menuOption){
case 1: recursiveTreeRunner();break;
case 2: drawCircleRunner();break;
case 3: drawSpiralRunner();break;
void drawSpiralRunner(){
int initialLength;
int alive = 1;
while(alive != 0){
drawSpiral(initialLength);
alive = 0;
}
}
if (length <= 0) {
return;
printf("*");
printf("\n");
drawSpiral(length - 1);
void drawCircleRunner(){
int initialRadius;
int centerX;
int alive = 1;
int centerY;
while(alive != 0){
alive = 0;
if (radius <= 0) {
return;
printf(".");
if (i % 36 == 0) {
printf("\n");
}
printf("\n");
void recursiveTreeRunner(){
int height;
int spaces;
int alive = 1;
while(alive != 0){
recursiveTree(height, spaces);
alive = 0;
if (height <= 0) {
return;
}
// Print spaces
printf(" ");
// Print asterisks
printf("*");
printf("\n");
void arrayProgram(){
printf(""
int menuOption = getUserInput("Choose sequential program example from the menu[1-4]: ",
"%d");
switch(menuOption){
case 1: sumOfFivenumber();break;
case 2: findTheLargestNumberInArray();break;
case 3: reverseArray();break;
void sumOfFivenumber(){
int alive = 1;
int limit = 5;
int numbers[10];
int sum = 0;
while(alive != 0){
sum += numbers[n];
alive = 0;
}
void findTheLargestNumberInArray(){
int alive = 1;
int limit = 5;
int numbers[5];
int max;
while(alive != 0){
max = numbers[n];
alive = 0;
int alive = 1;
int limit = 5;
int numbers[5];
int temp;
int i = 0, j = limit - 1;
while (i < j) {
// Loop body
temp = numbers[i];
numbers[i] = numbers[j];
numbers[j] = temp;
++i;
--j;
alive = 0;
}
// >>>>>>>>>>>>>>>>>> LOOP STRUCTURE <<<<<<<<<<<<<<<<<<<<
void loopProgram(){
printf(""
int menuOption = getUserInput("Choose sequential program example from the menu[1-4]: ",
"%d");
switch(menuOption){
case 1: forLoop();break;
case 2: whileLoop();break;
case 3: doWhileLoop();break;
void forLoop(){
int alive = 1;
while(alive != 0){
}
if(yesOrNoOption("Do you want to continue? ") == 1){
alive = 0;
void whileLoop(){
int alive = 1;
int userInput;
while(alive !=0){
alive = 0;
void doWhileLoop(){
int alive = 1;
int row;
int col;
char symbol;
while(alive !=0){
printf("\n");
alive = 0;
void decisionProgram(){
printf(""
"2. Calculator\n"
int menuOption = getUserInput("Choose sequential program example from the menu[1-4]: ",
"%d");
switch(menuOption){
case 1: gradeClassification();break;
case 2: calculator();break;
case 3: voteEligibility();break;
}
void gradeClassification(){
int marks;
int alive = 1;
while(alive != 0){
printf("Grade: A\n");
printf("Grade: B\n");
printf("Grade: C\n");
printf("Grade: D\n");
} else {
printf("Grade: F\n");
alive = 0;
}
// =======> CALCULATOR <=======
void calculator(){
char operators;
double result;
int alive = 1;
while(alive != 0){
switch (operators) {
alive = 0;
}
}
void voteEligibility(){
int age;
int alive = 1;
while(alive != 0){
} else {
alive = 0;
void sequentialProgram(){
printf(""
int menuOption = getUserInput("Choose sequential program example from the menu[1-4]: ",
"%d");
switch(menuOption){
case 1: calculateSumOfTwoNumbers();break;
case 2: areaOfACircle();break;
case 3: displayEvenNumbersLimit();break;
void calculateSumOfTwoNumbers(){
int alive = 1;
do{
alive = 0;
}while(alive != 0);
void areaOfACircle(){
int alive = 1;
while(alive != 0){
scanf("%f", &radius);
alive = 0;
}
}
void displayEvenNumbersLimit(){
// Declare variables
int limit;
int alive = 1;
while(alive != 0){
scanf("%d", &limit);
printf("\n");
alive = 0;
// TOOLS
/*
THIS FUNCTION WILL CHECK IF USER ENTER THE CORRECT DATATYPE!!
int scan_check: returns 1(as true) or 0(as false), if user entered the correct datatype it
will return 1 other wise 0;
int alive: This will terminate the code if scan_check returns 0 or false;
*/
int user_input;
while(alive){ // if the variable alive is equal to 0, then the loop will be terminated.
printf("%s", message);
if(scan_check == 1){
alive = 0;
}else{
}return user_input;
void removeBuffer(){
/*
*/
int c;
while ((c = getchar()) != '\n' && c != EOF);
/*
*/
char user_choice;
int alive = 1;
while(alive != 0){
printf("\n%s", message);
if(toupper(user_choice) == 'N'){
}else{