-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update file permissions and add new files
- Loading branch information
1 parent
7424b0e
commit 35aa2b8
Showing
29 changed files
with
873 additions
and
7 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "main.h" | ||
|
||
/** | ||
* main - check the code. | ||
* | ||
* Return: Always 0. | ||
*/ | ||
int main(void) | ||
{ | ||
print_times_table(3); | ||
_putchar('\n'); | ||
print_times_table(5); | ||
_putchar('\n'); | ||
print_times_table(98); | ||
_putchar('\n'); | ||
print_times_table(12); | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "main.h" | ||
|
||
/** | ||
* print_times_table - Prints the n times table, starting with 0. | ||
* @n: The value of the times table to be printed. | ||
*/ | ||
void print_times_table(int n) | ||
{ | ||
int row, column, product; | ||
|
||
if (n >= 0 && n <= 15) | ||
{ | ||
for (row = 0; row <= n; row++) | ||
{ | ||
for (column = 0; column <= n; column++) | ||
{ | ||
product = row * column; | ||
if (column != 0) | ||
{ | ||
_putchar(','); | ||
_putchar(' '); | ||
if (product < 10) | ||
{ | ||
_putchar(' '); | ||
_putchar(' '); | ||
} | ||
else if (product < 100) | ||
{ | ||
_putchar(' '); | ||
} | ||
} | ||
if (product >= 100) | ||
{ | ||
_putchar((product / 100) + '0'); | ||
_putchar(((product / 10) % 10) + '0'); | ||
} | ||
else if (product >= 10) | ||
{ | ||
_putchar((product / 10) + '0'); | ||
} | ||
_putchar((product % 10) + '0'); | ||
} | ||
_putchar('\n'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <stdio.h> | ||
|
||
/** | ||
* main - Computes and prints the sum of all the multiples of 3 or 5 below 1024 | ||
* | ||
* Return: Always 0. | ||
*/ | ||
int main(void) | ||
{ | ||
int i, sum = 0; | ||
|
||
for (i = 0; i < 1024; i++) | ||
{ | ||
if (i % 3 == 0 || i % 5 == 0) | ||
{ | ||
sum += i; | ||
} | ||
} | ||
|
||
printf("%d\n", sum); | ||
|
||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <stdio.h> | ||
|
||
/** | ||
* main - Prints the first 50 Fibonacci numbers, starting with 1 and 2 | ||
* | ||
* Return: Always 0. | ||
*/ | ||
int main(void) | ||
{ | ||
long int i, j, k, next; | ||
|
||
j = 1; | ||
k = 2; | ||
|
||
printf("%ld, %ld", j, k); | ||
for (i = 3; i <= 50; i++) | ||
{ | ||
next = j + k; | ||
j = k; | ||
k = next; | ||
printf(", %ld", next); | ||
} | ||
printf("\n"); | ||
|
||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <stdio.h> | ||
|
||
/** | ||
* main - Prints the sum of the even-valued Fibonacci sequence terms not | ||
* exceeding 4,000,000. | ||
* | ||
* Return: Always 0. | ||
*/ | ||
int main(void) | ||
{ | ||
unsigned long int i = 0, j = 1, sum = 0; | ||
unsigned long int k; | ||
|
||
while (1) | ||
{ | ||
k = i + j; | ||
if (k > 4000000) | ||
break; | ||
|
||
if (k % 2 == 0) | ||
sum += k; | ||
|
||
i = j; | ||
j = k; | ||
} | ||
|
||
printf("%lu\n", sum); | ||
|
||
return (0); | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Oops, something went wrong.