From d06a6a89cea286a2721002ac555a19c5e9b8f0f3 Mon Sep 17 00:00:00 2001 From: sujay Date: Tue, 15 Nov 2022 13:10:37 +0000 Subject: [PATCH] files added --- big2.c | 22 ++++++++++++++++++++++ fact.c | 19 +++++++++++++++++++ main.c | 7 +++++++ rev.c | 24 ++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 big2.c create mode 100644 fact.c create mode 100644 main.c create mode 100644 rev.c diff --git a/big2.c b/big2.c new file mode 100644 index 0000000..30bec31 --- /dev/null +++ b/big2.c @@ -0,0 +1,22 @@ +#include +biggest() +{ + int num1, num2; + // Ask user to enter the two numbers + printf("Please Enter Two different values\n"); + // Read two numbers from the user + scanf("%d %d", &num1, &num2); + if(num1 > num2) + { + printf("%d is Largest\n", num1); + } + else if (num2 > num1) + { + printf("%d is Largest\n", num2); + } + else + { + printf("Both are Equal\n"); + } + // return 0; +} diff --git a/fact.c b/fact.c new file mode 100644 index 0000000..f4a44e5 --- /dev/null +++ b/fact.c @@ -0,0 +1,19 @@ +#include + factorial() { + int n, i; + unsigned long long fact = 1; + printf("Enter 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."); + else { + for (i = 1; i <= n; ++i) { + fact *= i; + } + printf("Factorial of %d = %llu", n, fact); + } + + // return 0; +} diff --git a/main.c b/main.c new file mode 100644 index 0000000..2d0677f --- /dev/null +++ b/main.c @@ -0,0 +1,7 @@ +#include +main() { + + biggest(); + factorial(); + reverse(); +} diff --git a/rev.c b/rev.c new file mode 100644 index 0000000..c14a19f --- /dev/null +++ b/rev.c @@ -0,0 +1,24 @@ +#include +reverse() +{ + char str[1000], rev[1000]; + int i, j, count = 0; +printf("\nEnter string to reverse"); + scanf("%s", str); + printf("\nString Before Reverse: %s", str); + //finding the length of the string + while (str[count] != '\0') + { + count++; + } + j = count - 1; + + //reversing the string by swapping + for (i = 0; i < count; i++) + { + rev[i] = str[j]; + j--; + } + + printf("\nString After Reverse: %s", rev); +}