Skip to content

Commit

Permalink
Update file permissions and add new files
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWatcher01 committed Apr 3, 2024
1 parent 7424b0e commit 35aa2b8
Show file tree
Hide file tree
Showing 29 changed files with 873 additions and 7 deletions.
Empty file modified functions_nested_loops/1-main.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/10-add.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/10-main.c
100644 → 100755
Empty file.
18 changes: 18 additions & 0 deletions functions_nested_loops/100-main.c
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);
}
46 changes: 46 additions & 0 deletions functions_nested_loops/100-times_table.c
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');
}
}
}
23 changes: 23 additions & 0 deletions functions_nested_loops/101-natural.c
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);
}
26 changes: 26 additions & 0 deletions functions_nested_loops/102-fibonacci.c
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);
}
30 changes: 30 additions & 0 deletions functions_nested_loops/103-fibonacci.c
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 modified functions_nested_loops/11-main.c
100644 → 100755
Empty file.
22 changes: 16 additions & 6 deletions functions_nested_loops/11-print_to_98.c
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
#include <stdio.h>
#include "main.h"

/**
* print_to_98 - Prints all natural numbers from n to 98
* @n: The number to start printing from
*
* Return: Always 0.
*/
* 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);
}
void print_to_98(int n)
{
int i;
Expand Down
Empty file modified functions_nested_loops/2-main.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/2-print_alphabet_x10.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/3-islower.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/3-main.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/4-isalpha.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/4-main.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/5-main.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/5-sign.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/6-abs.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/6-main.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/7-main.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/7-print_last_digit.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/8-24_hours.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/8-main.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/9-main.c
100644 → 100755
Empty file.
Empty file modified functions_nested_loops/9-times_table.c
100644 → 100755
Empty file.
Loading

0 comments on commit 35aa2b8

Please sign in to comment.