Skip to content

Commit c16db67

Browse files
committed
main.h
1 parent 639be66 commit c16db67

File tree

9 files changed

+245
-0
lines changed

9 files changed

+245
-0
lines changed

0x02-functions_nested_loops/.swp

12 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "main.h"
2+
3+
/**
4+
* print_times_table - prints the n times table, starting with 0
5+
* @n: number of the times table
6+
*/
7+
void print_times_table(int n)
8+
{
9+
int i, j, k;
10+
11+
if (n >= 0 && n <= 15)
12+
{
13+
for (i = 0; i <= n; i++)
14+
{
15+
for (j = 0; j <= n; j++)
16+
{
17+
k = j * i;
18+
if (j == 0)
19+
{
20+
_putchar(k + '0');
21+
} else if (k < 10 && j != 0)
22+
{
23+
_putchar(',');
24+
_putchar(' ');
25+
_putchar(' ');
26+
_putchar(' ');
27+
_putchar(k + '0');
28+
} else if (k >= 10 && k < 100)
29+
{
30+
_putchar(',');
31+
_putchar(' ');
32+
_putchar(' ');
33+
_putchar((k / 10) + '0');
34+
_putchar((k % 10) + '0');
35+
} else if (k >= 100)
36+
{
37+
_putchar(',');
38+
_putchar(' ');
39+
_putchar((k / 100) + '0');
40+
_putchar(((k / 10) % 10) + '0');
41+
_putchar((k % 10) + '0');
42+
}
43+
}
44+
_putchar('\n');
45+
}
46+
}
47+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* File: 101-natural.c
3+
* Auth: vincent kip
4+
*/
5+
6+
#include <stdio.h>
7+
8+
/**
9+
* main - Lists all the natural numbers below 1024 (excluded)
10+
* that are multiples of 3 or 5.
11+
*
12+
* Return: Always 0.
13+
*/
14+
int main(void)
15+
{
16+
int i, sum = 0;
17+
18+
for (i = 0; i < 1024; i++)
19+
{
20+
if ((i % 3) == 0 || (i % 5) == 0)
21+
sum += i;
22+
}
23+
24+
printf("%d\n", sum);
25+
26+
return (0);
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <stdio.h>
2+
3+
/**
4+
* main - Prints first 50 Fibonacci numbers, starting with 1 and 2,
5+
* separated by a comma followed by a space.
6+
*
7+
* Return: Always 0.
8+
*/
9+
int main(void)
10+
{
11+
int count;
12+
unsigned long fib1 = 0, fib2 = 1, sum;
13+
14+
for (count = 0; count < 50; count++)
15+
{
16+
sum = fib1 + fib2;
17+
printf("%lu", sum);
18+
19+
fib1 = fib2;
20+
fib2 = sum;
21+
22+
if (count == 49)
23+
printf("\n");
24+
else
25+
printf(", ");
26+
}
27+
28+
return (0);
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <stdio.h>
2+
3+
/**
4+
* main - finds and prints the sum of the even-valued terms
5+
* followed by a new line
6+
* Return: Always 0 (Success)
7+
*/
8+
int main(void)
9+
{
10+
int i;
11+
unsigned long int j, k, next, sum;
12+
13+
j = 1;
14+
k = 2;
15+
sum = 0;
16+
17+
for (i = 1; i <= 33; ++i)
18+
{
19+
if (j < 4000000 && (j % 2) == 0)
20+
{
21+
sum = sum + j;
22+
}
23+
next = j + k;
24+
j = k;
25+
k = next;
26+
}
27+
28+
printf("%lu\n", sum);
29+
30+
return (0);
31+
}
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <stdio.h>
2+
3+
/**
4+
* main - fibonacci <3
5+
*
6+
* Purpose - no hardcode
7+
*
8+
* Return: (Success)
9+
*/
10+
11+
int main(void)
12+
{
13+
unsigned long int i;
14+
unsigned long int bef = 1;
15+
unsigned long int aft = 2;
16+
unsigned long int l = 1000000000;
17+
unsigned long int bef1;
18+
unsigned long int bef2;
19+
unsigned long int aft1;
20+
unsigned long int aft2;
21+
22+
printf("%lu", bef);
23+
24+
for (i = 1; i < 91; i++)
25+
{
26+
printf(", %lu", aft);
27+
aft += bef;
28+
bef = aft - bef;
29+
}
30+
31+
bef1 = (bef / l);
32+
bef2 = (bef % l);
33+
aft1 = (aft / l);
34+
aft2 = (aft % l);
35+
36+
for (i = 92; i < 99; ++i)
37+
{
38+
printf(", %lu", aft1 + (aft2 / l));
39+
printf("%lu", aft2 % l);
40+
aft1 = aft1 + bef1;
41+
bef1 = aft1 - bef1;
42+
aft2 = aft2 + bef2;
43+
bef2 = aft2 - bef2;
44+
}
45+
printf("\n");
46+
return (0);
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <stdio.h>
2+
#include "main.h"
3+
4+
/**
5+
* print_to_98 - prints all natural numbers from n to 98,
6+
* followed by a new line
7+
* @n: print from this number
8+
*/
9+
void print_to_98(int n)
10+
{
11+
int i, j;
12+
13+
if (n <= 98)
14+
{
15+
for (i = n; i <= 98; i++)
16+
{
17+
if (i != 98)
18+
printf("%d, ", i);
19+
else if (i == 98)
20+
printf("%d\n", i);
21+
}
22+
} else if (n >= 98)
23+
{
24+
for (j = n; j >= 98; j--)
25+
{
26+
if (j != 98)
27+
printf("%d, ", j);
28+
else if (j == 98)
29+
printf("%d\n", j);
30+
}
31+
}
32+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "main.h"
2+
#include <unistd.h>
3+
/**
4+
* _putchar - writes the character c to stdout
5+
* @c: The character to print
6+
*
7+
* Return: On success 1.
8+
* On error, -1 is returned, and errno is set appropriately.
9+
*/
10+
int _putchar(char c)
11+
{
12+
return (write(1, &c, 1));
13+
}

0x02-functions_nested_loops/main.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef main_h
2+
#define main_h
3+
4+
int _putchar(char);
5+
void print_alphabet(void);
6+
void print_alphabet_x10(void);
7+
int _islower(int c);
8+
int _isalpha(int c);
9+
int print_sign(int n);
10+
int _abs(int);
11+
int print_last_digit(int);
12+
void jack_bauer(void);
13+
void times_table(void);
14+
int add(int, int);
15+
void print_to_98(int n);
16+
void print_times_table(int n);
17+
18+
#endif

0 commit comments

Comments
 (0)