Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Low_level_programming

alx-low_level_programming/0x03-debugging

Mkdir 0x03-debugging directory

Touch main.h or vi main.h

#ifndef MAIN_H
#define MAIN_H
#include <stdio.h>
void positive_or_negative(int i);
int largest_number(int a, int b, int c);
int convert_day(int month, int day);
void print_remaining_days(int month, int day, int year);
#endif /* MAIN_H */

echo README.md

echo "description of the project" > README.md

Debugging TASK 1 – 0-main.c

#include "main.h"

/**
 * main - tests function that prints if integer is positive or negative
 * Return: 0
 */

int main(void)
{
	int i;

	i = 0;
	positive_or_negative(i);

	return (0);
}

TASK 2 – 1-main.c

#include <stdio.h>

/**
 * main - causes an infinite loop
 * Return: 0
 */

int main(void)
{
	int i;

	printf("Infinite loop incoming :(\n");

	i = 0;
/*
*	while (i < 10)
*	{
*		putchar(i);
*	}
*/
	printf("Infinite loop avoided! \\o/\n");

	return (0);
}

TASK 3 – 2-largest-number.c

#include "main.h"

/**
 * largest_number - returns the largest of 3 numbers
 * @a: first integer
 * @b: second integer
 * @c: third integer
 * Return: largest number
 */
int largest_number(int a, int b, int c)
{
	int largest;

	if (a > b && a > c)
	{
		largest = a;
	}
	else if (b > c)
	{
		largest = b;
	}
	else
	{
		largest = c;
	}

	return (largest);
}

TASK 4 – 3-print_remaining_days.c

#include <stdio.h>
#include "main.h"

/**
 * print_remaining_days - takes a date and prints how many days are
 * left in the year, taking leap years into account
 * @month: month in number format
 * @day: day of month
 * @year: year
 * Return: void
 */

void print_remaining_days(int month, int day, int year)
{
	if (year % 4 == 0 || (year % 400 == 0 && year % 100 == 0))
	{
		if (month > 2 && day >= 60)
		{
			day++;
		}

		printf("Day of the year: %d\n", day);
		printf("Remaining days: %d\n", 366 - day);
	}
	else
	{
		if (month == 2 && day == 60)
		{
			printf("Invalid date: %02d/%02d/%04d\n", month, day - 31, year);
		}
		else
		{
			printf("Day of the year: %d\n", day);
			printf("Remaining days: %d\n", 365 - day);
		}
	}
}

NB: Do you know you can git commit all your files and push at once?

To make that happen, complete each code and git add, then git commit. and move to the next one.

just to be sure if your work is ok, you can compile the file using make filename without the .c extension and run with ./filename.c

#Leave comments below if you have any questions.

#Share this if you find it useful.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
Low_level_programming

alxlow_level_programming/0x02-functions_nested_loops/

Next Post
Low_level_programming

alx-low_level_programming/0x04-more_functions_nested_loops

Please Leave a comment on comment section, let me know what you think about this article.

Related Posts
Hey, if you have any questions and want to talk to one of our specialists chat up here:
Chat me up