initial commit
This commit is contained in:
8 files changed
+250
No files matched your search
@@ -0,0 +1,25 @@
|
||||
# Makefile
|
||||
# Compiler and flags
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -std=c11
|
||||
|
||||
# Source files
|
||||
SRCS = lab2.c
|
||||
|
||||
# Output
|
||||
TARGET = lab2.out
|
||||
|
||||
# Default target
|
||||
all: $(TARGET)
|
||||
|
||||
# Rule to build the executable
|
||||
$(TARGET): $(SRCS)
|
||||
$(CC) $(CFLAGS) $(SRCS) -o $(TARGET)
|
||||
|
||||
# Rule to run the program
|
||||
run: $(TARGET)
|
||||
./$(TARGET)
|
||||
|
||||
# Rule to clean generated files
|
||||
clean:
|
||||
rm -f $(TARGET)
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void multiplicationTable(int n) {
|
||||
printf("Multiplication table of %d\n", n);
|
||||
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
printf("%d x %d = %d\n", n, i, n * i);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void numberAnalysis(int n) {
|
||||
int c = (n > 0) - (n < 0);
|
||||
|
||||
switch (c) {
|
||||
case -1: // n is negative
|
||||
multiplicationTable(n);
|
||||
|
||||
printf("Sum not applicable for negative numbers\n");
|
||||
printf("The number is Negative.\n");
|
||||
|
||||
break;
|
||||
case 0: // n is zero
|
||||
multiplicationTable(n);
|
||||
|
||||
printf("Sum not applicable for zero\n");
|
||||
printf("The number is Zero.\n");
|
||||
|
||||
break;
|
||||
default: // n is positive
|
||||
multiplicationTable(n);
|
||||
|
||||
int sum = 0;
|
||||
int current = 0;
|
||||
while (current <= n) {
|
||||
sum += current;
|
||||
current++;
|
||||
}
|
||||
|
||||
printf("Sum of 1 to %d = %d\n", n, sum);
|
||||
printf("The number is Positive.\n");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int number;
|
||||
|
||||
printf("Enter a number: ");
|
||||
scanf("%d", &number);
|
||||
|
||||
numberAnalysis(number);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
Reference in new issue
Block a user