Skip to content

Commit

Permalink
10 | 19- 20 | sharafat
Browse files Browse the repository at this point in the history
  • Loading branch information
SharafatKarim committed Aug 4, 2023
1 parent 532f137 commit 003e5a8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
14 changes: 14 additions & 0 deletions solutions/sharafat/10/18.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
#include <stdio.h>

char *month_name(int m)
{
char *months[] = {
"January", "February", "March", "April", "May", "June", "July", "August",
"September", "October", "November", "December"};

return months[m - 1];
}

int main()
{
int m;

printf("Enter month number: ");
scanf("%d", &m);

printf("Month name: %s\n", month_name(m));

return 0;
}
28 changes: 28 additions & 0 deletions solutions/sharafat/10/19.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>

int leap(int year)
{
if (year % 400 == 0)
return 1;
else if (year % 100 == 0)
return 0;
else if (year % 4 == 0)
return 1;
else
return 0;
}

int main()
{
int year;

printf("Enter year: ");
scanf("%d", &year);

if (leap(year))
printf("%d is a leap year.\n", year);
else
printf("%d is not a leap year.\n", year);

return 0;
}
19 changes: 19 additions & 0 deletions solutions/sharafat/10/20.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>
#include <math.h>

double round2(double x)
{
return round(x * 100) / 100;
}

int main()
{
double x;

printf("Enter a floating point value: ");
scanf("%lf", &x);

printf("Rounded value: %.2lf\n", round2(x));

return 0;
}

0 comments on commit 003e5a8

Please sign in to comment.