Algorithm
Algorithm
Start
Step 1-> declare function to calculate distance between two point
void three_dis(float a, float x, float b, float y)
set float dis = sqrt(pow(b - a / 2) + pow(y - z / 2) * 1.0)
print dis
step 2-> In main()
Set float a = 4
Set float x = 9
Set float b = 5
Set float y = 10
Call two_dis(a, x, b, y)
Stop
Flowchart:
2) Source Code:
#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
scanf(" %c", &c);
printf("Character: %c\n", c);
printf("ASCII Value: %d\n", c);
return 0;
}
Input:
Enter a character: A
Output:
Character: A
ASCII Value: 65
3) Source Code:
#include <stdio.h>
int main() {
int choice, subChoice;
double side, length, width, base, height, area, perimeter;
do {
printf("*MAIN MENU*\n");
printf("[1] SQUARE\n");
printf("[2] RECTANGLE\n");
printf("[3] TRIANGLE\n");
printf("[4] EXIT\n");
printf("SELECT A CHOICE: ");
scanf("%d", &choice);
switch (choice) {
case 1: // Square
printf("[A] COMPUTE FOR AREA\n");
printf("[B] COMPUTE FOR PERIMETER\n");
printf("[C] COMPUTE FOR AREA AND PERIMETER\n");
printf("SELECT A CHOICE: ");
scanf(" %c", &subChoice);
case 2: // Rectangle
printf("[A] COMPUTE FOR AREA\n");
printf("[B] COMPUTE FOR PERIMETER\n");
printf("[C] COMPUTE FOR AREA AND PERIMETER\n");
printf("SELECT A CHOICE: ");
scanf(" %c", &subChoice);
case 3: // Triangle
printf("[A] COMPUTE FOR AREA\n");
printf("[B] COMPUTE FOR PERIMETER\n");
printf("[C] COMPUTE FOR AREA AND PERIMETER\n");
printf("SELECT A CHOICE: ");
scanf(" %c", &subChoice);
case 4: // Exit
printf("Goodbye!\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
if (choice != 4) {
int goBackChoice;
printf("DO YOU WANT TO GO BACK TO MAIN MENU?\n");
printf("[1] YES\n");
printf("[2] NO\n");
printf("SELECT A CHOICE: ");
scanf("%d", &goBackChoice);
if (goBackChoice != 1)
choice = 4; // Exit the program if the user chooses not to go back
to the main menu
}
} while (choice != 4);
return 0;}