Skip to content
This repository was archived by the owner on Jul 13, 2025. It is now read-only.

Commit 90b3ddd

Browse files
C
1 parent 24e3289 commit 90b3ddd

15 files changed

+320
-0
lines changed

Arithmetic Problems/powers.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// First Three Powers (N^1, N^2, N^3) Without Using Power Function
2+
3+
/*
4+
Explanation:
5+
N = N;
6+
N^2 = N*N;
7+
N^3 = N*N*N;
8+
N^4 = N*N*N*N;
9+
*/
10+
#include<stdio.h>
11+
int main()
12+
{
13+
int num;
14+
printf("Please enter the number: ");
15+
scanf("%d", &num);
16+
17+
printf("The three first numbers: %d, %d and %d\n", num, num*num, num*num*num);
18+
return 0;
19+
}

Arithmetic Problems/powers.exe

383 KB
Binary file not shown.

Arithmetic Problems/powers_function.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// First Three Powers (N^1, N^2, N^3) Using Power Function
2+
/*
3+
Power Function:
4+
pow(var, power) e.g., pow(num, 2)
5+
*/
6+
#include<stdio.h>
7+
int main()
8+
{
9+
int a, b, c, num;
10+
printf("Please enter the number: ");
11+
scanf("%d", &num);
12+
13+
a = pow(num, 1);
14+
b = pow(num, 2);
15+
c = pow(num, 3);
16+
17+
printf("The three first numbers: %d, %d and %d\n", a, b, c);
18+
return 0;
19+
}
402 KB
Binary file not shown.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Check whether the a date is valid or not.
2+
/*
3+
Condition:
4+
Date: 1<= date <= 31;
5+
Month: 1<= month <= 12;
6+
Year: 1<= year <=12
7+
8+
Note:
9+
If the year is a leap year then February month will be 29. Otherwise 28.
10+
If the
11+
*/
12+
13+
14+
#include<stdio.h>
15+
#include<conio.h>
16+
void main()
17+
{
18+
int d,m,y,i,leap=0,temp=0,temp1=0,temp2=0;
19+
20+
printf("C Program to Date Validation");
21+
22+
while(1)
23+
{
24+
printf("\n\nEnter The Date (dd mm yyyy) : ");
25+
scanf(" %d %d %d",&d,&m,&y);
26+
27+
if(y<1600||y>2100)
28+
{
29+
printf("\nYear Is Not Valid !!!! Try Again");
30+
temp=1;
31+
}
32+
else
33+
{
34+
printf("\nYear Is Valid ");
35+
}
36+
37+
if(temp!=1)
38+
{
39+
if(y%4==0)
40+
leap=1;
41+
}
42+
43+
if(m<1||m>12)
44+
{
45+
printf("\nMonth Is Not Valid !!!! Try Again");
46+
}
47+
else
48+
{
49+
printf("\nMonth Is Valid ");
50+
}
51+
52+
if(d<1||d>31)
53+
{
54+
temp2=1;
55+
}
56+
57+
if(m>=1&&m<=7)
58+
{
59+
for(i=1;i<=6;i++)
60+
{
61+
if(m%2==0)
62+
temp1=30;
63+
if(m%2==1)
64+
temp1=31;
65+
}
66+
}
67+
68+
if(leap==0&&m==2)
69+
{
70+
temp1=28;
71+
}
72+
73+
if(leap==1&&m==2)
74+
{
75+
temp1=29;
76+
}
77+
78+
if(m>=8&&m<=12)
79+
{
80+
for(i=7;i<=12;i++)
81+
{
82+
if(m%2==0)
83+
temp1=31;
84+
if(m%2==1)
85+
temp1=30;
86+
}
87+
}
88+
if(d>temp1)
89+
temp2=1;
90+
if(temp2==1)
91+
printf("\nDate Is Not Valid !!!!! Try Again");
92+
if(temp2==0)
93+
printf("\nDate Is Valid ");
94+
95+
printf("\n\n\nPress Enter For Again Check Date Validity \n");
96+
getch();
97+
}
98+
}
Binary file not shown.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Check you are elligible for voting or not.
2+
3+
#include<stdio.h>
4+
int main()
5+
{
6+
int BirthYear, PresentYear, Age, wait;
7+
PresentYear = 2023;
8+
printf("Enter your Birthyear: ");
9+
scanf("%d", &BirthYear);
10+
11+
Age= PresentYear - BirthYear;
12+
13+
if(Age>=18 && Age<100)
14+
{
15+
printf("You are eligible to vote!\n");
16+
}
17+
else if(Age>100)
18+
{
19+
printf("You are eligible but we prefer to take rest at home!\n");
20+
}
21+
else
22+
{
23+
wait = 18 - Age;
24+
printf("Sorry,you are not eligible to vote!\nPlease wait %d years to vote!\n", wait);
25+
}
26+
return 0;
27+
28+
}
383 KB
Binary file not shown.

If_Else Statements/ever_or_odd.exe

0 Bytes
Binary file not shown.

If_Else Statements/leap_year.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Calculate whether a year is a leap year or not!
2+
/*
3+
Condition:
4+
The year should be divisible by 4 AND year % 100 != 0.
5+
Year % 400 = 0
6+
7+
Syntax: ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)
8+
*/
9+
10+
#include<stdio.h>
11+
int main()
12+
{
13+
int year;
14+
printf("Please enter year: ");
15+
scanf("%d", &year);
16+
17+
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
18+
{
19+
printf("%d is a leap year!\n", year);
20+
}
21+
else
22+
{
23+
printf("%d is not a leap year!\n", year);
24+
}
25+
return 0;
26+
}
27+
28+
29+
30+

0 commit comments

Comments
 (0)