-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathstudent_basic_program.c
More file actions
82 lines (68 loc) · 2.48 KB
/
student_basic_program.c
File metadata and controls
82 lines (68 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* ==============================================================
File Name : student_basic_program.c
Author : Agnibesh Maity
Description : A simple C program that performs basic operations:
1. Print a greeting
2. Calculate sum of two numbers
3. Check even or odd
4. Find factorial of a number
Created On : October 2025
============================================================== */
#include <stdio.h>
// --------------------------------------------------------------
// Function to calculate factorial
// --------------------------------------------------------------
int factorial(int n) {
int fact = 1;
for (int i = 1; i <= n; i++)
fact *= i;
return fact;
}
// --------------------------------------------------------------
// Main Function
// --------------------------------------------------------------
int main() {
int choice, a, b, n;
printf("=============================================\n");
printf("🧠 BASIC C PROGRAM - MULTI FUNCTION TOOL 🧠\n");
printf("=============================================\n");
printf("1️⃣ Print Greeting Message\n");
printf("2️⃣ Sum of Two Numbers\n");
printf("3️⃣ Check Even or Odd\n");
printf("4️⃣ Find Factorial\n");
printf("5️⃣ Exit\n");
printf("---------------------------------------------\n");
while (1) {
printf("\nEnter your choice (1-5): ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("\nHello, World! 🌎 Welcome to C Programming!\n");
break;
case 2:
printf("\nEnter two numbers: ");
scanf("%d %d", &a, &b);
printf("Sum = %d\n", a + b);
break;
case 3:
printf("\nEnter a number: ");
scanf("%d", &n);
if (n % 2 == 0)
printf("%d is Even.\n", n);
else
printf("%d is Odd.\n", n);
break;
case 4:
printf("\nEnter a number: ");
scanf("%d", &n);
printf("Factorial of %d = %d\n", n, factorial(n));
break;
case 5:
printf("\n👋 Exiting... Have a great day!\n");
return 0;
default:
printf("⚠️ Invalid choice! Try again.\n");
}
}
return 0;
}