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
23 changes: 23 additions & 0 deletions C/Bin_To_Dec.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>
#include <conio.h>
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();
}
20 changes: 20 additions & 0 deletions C/Dec_To_Bin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>
#include <stdlib.h>
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;
}
29 changes: 29 additions & 0 deletions C/Duck_Number.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>

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");
}
}
35 changes: 35 additions & 0 deletions C/Leap_Year.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <stdio.h>
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;
}