From fab959a47f164aa20c630118cafa8dfca73e9505 Mon Sep 17 00:00:00 2001 From: Prankush Giri <76916192+prankush-tech@users.noreply.github.com> Date: Thu, 6 Oct 2022 13:16:25 +0530 Subject: [PATCH] Added leap year, Duck number, Dec to BIn vise versa --- C/Bin_To_Dec.c | 23 +++++++++++++++++++++++ C/Dec_To_Bin.c | 20 ++++++++++++++++++++ C/Duck_Number.c | 29 +++++++++++++++++++++++++++++ C/Leap_Year.c | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 C/Bin_To_Dec.c create mode 100644 C/Dec_To_Bin.c create mode 100644 C/Duck_Number.c create mode 100644 C/Leap_Year.c diff --git a/C/Bin_To_Dec.c b/C/Bin_To_Dec.c new file mode 100644 index 0000000..7b807e7 --- /dev/null +++ b/C/Bin_To_Dec.c @@ -0,0 +1,23 @@ +#include +#include +void main() +{ + // declaration of variables + int num, binary_num, decimal_num = 0, base = 1, rem; + printf(" Enter a binary number with the combination of 0s and 1s \n"); + scanf(" %d", &num); // accept the binary number (0s and 1s) + + binary_num = num; // assign the binary number to the binary_num variable + + while (num > 0) + { + rem = num % 10; /* divide the binary number by 10 and store the remainder in rem variable. */ + decimal_num = decimal_num + rem * base; + num = num / 10; // divide the number with quotient + base = base * 2; + } + + printf(" The binary number is %d \t", binary_num); // print the binary number + printf(" \n The decimal number is %d \t", decimal_num); // print the decimal + getch(); +} \ No newline at end of file diff --git a/C/Dec_To_Bin.c b/C/Dec_To_Bin.c new file mode 100644 index 0000000..f3231e9 --- /dev/null +++ b/C/Dec_To_Bin.c @@ -0,0 +1,20 @@ +#include +#include +int main() +{ + int a[10], n, i; + system("cls"); + printf("Enter the number to convert: "); + scanf("%d", &n); + for (i = 0; n > 0; i++) + { + a[i] = n % 2; + n = n / 2; + } + printf("\nBinary of Given Number is="); + for (i = i - 1; i >= 0; i--) + { + printf("%d", a[i]); + } + return 0; +} \ No newline at end of file diff --git a/C/Duck_Number.c b/C/Duck_Number.c new file mode 100644 index 0000000..58e417b --- /dev/null +++ b/C/Duck_Number.c @@ -0,0 +1,29 @@ +#include +#include + +int main() +{ + int dno, dkno, r, flg; + flg = 0; + printf("\n\n Check whether a number is a Duck Number or not: \n"); + printf(" Input a number: "); + scanf("%d", &dkno); + dno = dkno; + while (dkno > 0) + { + if (dkno % 10 == 0) + { + flg = 1; + break; + } + dkno /= 10; + } + if (dno > 0 && flg == 1) + { + printf(" The given number is a Duck Number.\n"); + } + else + { + printf(" The given number is not a Duck Number.\n"); + } +} diff --git a/C/Leap_Year.c b/C/Leap_Year.c new file mode 100644 index 0000000..8c5d950 --- /dev/null +++ b/C/Leap_Year.c @@ -0,0 +1,35 @@ +#include +int main() + +{ + int year; + printf("Enter a year: "); + scanf("%d", &year); + + // leap year if perfectly divisible by 400 + if (year % 400 == 0) + { + printf("%d is a leap year.", year); + } + + // not a leap year if divisible by 100 + // but not divisible by 400 + else if (year % 100 == 0) + + { + printf("%d is not a leap year.", year); + } + // leap year if not divisible by 100 + // but divisible by 4 + else if (year % 4 == 0) + { + printf("%d is a leap year.", year); + } + // all other years are not leap years + else + { + printf("%d is not a leap year.", year); + } + + return 0; +} \ No newline at end of file