Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions big3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>
void biggest3()
{
int A, B, C;

printf("\nEnter the numbers A, B and C: ");
scanf("%d %d %d", &A, &B, &C);

// finding max using compound expressions
if (A >= B && A >= C)
printf("%d is the largest number.\n", A);

else if (B >= A && B >= C)
printf("%d is the largest number.\n", B);

else
printf("%d is the largest number.\n", C);

}

20 changes: 20 additions & 0 deletions fact.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>
void factorial() {
int n, i;
unsigned long long fact = 1;
printf("\n\nEnter an integer: ");
scanf("%d", &n);

// shows error if the user enters a negative integer
if (n < 0)
printf("Error! Factorial of a negative number doesn't exist.\n");
else {
for (i = 1; i <= n; ++i) {
fact *= i;
}
printf("Factorial of %d = %llu\n", n, fact);
}

// return 0;
}

5 changes: 5 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
main() {
biggest3();
factorial();
pallydrome();
}
10 changes: 10 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ABC.exe:main.o big3.o fact.o pal.o
gcc -o ABC.exe main.o big3.o fact.o pal.o
main.o:main.c
gcc -c main.c
big3.o:big3.c
gcc -c big3.c
fact.o:fact.c
gcc -c fact.c
pal.o:pal.c
gcc -c pal.c
22 changes: 22 additions & 0 deletions pal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
void pallydrome() {
int n, reversed = 0, remainder, original;
printf("\nEnter an integer: ");
scanf("%d", &n);
original = n;

// reversed integer is stored in reversed variable
while (n != 0) {
remainder = n % 10;
reversed = reversed * 10 + remainder;
n /= 10;
}

// palindrome if orignal and reversed are equal
if (original == reversed)
printf("%d is a palindrome.\n", original);
else
printf("%d is not a palindrome\n.", original);

// return 0;
}