0x01-variables_if_else_while
0-positive_or_negative.c
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
/**
* main - Prints a random number and states whether
* it is positive, negative, or zero.
*
* Return: Always 0.
*/
int main(void)
{
int n;
srand(time(0));
n = rand() - RAND_MAX / 2;
/* your code goes there*/
if (n > 0)
printf("%d is positive\n", n);
else if (n < 0)
printf("%d is negative\n", n);
else
printf("%d is zero\n", n);
return (0);
}
1-last_digit.c
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
/**
* main - Prints the last digit of a randomly generated number
* and whether it is greater than 5, less than 6, or 0.
*
* Return: Always 0.
*/
int main(void)
{
int n;
srand(time(0));
n = rand() - RAND_MAX / 2;
/* your code goes there*/
if ((n % 10) > 5)
{
printf("Last digit of %d is %d and is greater than 5\n", n, n % 10);
}
else if ((n % 10) < 6 && (n % 10) != 0)
{
printf("Last digit of %d is %d and is less than 6 and not 0\n", n, n % 10);
}
else
{
printf("Last digit of %d is %d and is 0\n", n, n % 10);
}
return (0);
}
2-print_alphabet.c
#include <stdio.h>
/**
* main - Prints the alphabet in lowercase.
*
* Return: Always 0.
*/
int main(void)
{
char letter;
for (letter = 'a'; letter <= 'z'; letter++)
putchar(letter);
putchar('\n');
return (0);
}
3-print_alphabets.c
#include <stdio.h>
/**
* main - Prints the alphabet in lowercase, and then in uppercase.
*
* Return: Always 0.
*/
int main(void)
{
char letter;
for (letter = 'a'; letter <= 'z'; letter++)
putchar(letter);
for (letter = 'A'; letter <= 'Z'; letter++)
putchar(letter);
putchar('\n');
return (0);
}
4-print_alphabt.c
#include <stdio.h>
/**
* main - Prints the alphabet in lowercase, except for q and e.
*
* Return: Always 0.
*/
int main(void)
{
char letter;
for (letter = 'a'; letter <= 'z'; letter++)
{
if (letter != 'e' && letter != 'q')
putchar(letter);
}
putchar('\n');
return (0);
}
5-print_numbers.c
#include <stdio.h>
/**
* main - Prints all single digit numbers of base 10 starting from 0.
*
* Return: Always 0.
*/
int main(void)
{
int num;
for (num = 0; num < 10; num++)
printf("%d", num);
printf("\n");
return (0);
}
6-print_numberz.c
#include <stdio.h>
/**
* main - Prints all single digit numbers of base 10 starting from 0,
* only using putchar and without char variables.
*
* Return: Always 0.
*/
int main(void)
{
int num;
for (num = 0; num < 10; num++)
putchar((num % 10) + '0');
putchar('\n');
return (0);
}
7-print_tebahpla.c
#include <stdio.h>
/**
* main - Prints the lowercase alphabet in reverse.
*
* Return: Always 0.
*/
int main(void)
{
char letter;
for (letter = 'z'; letter >= 'a'; letter--)
putchar(letter);
putchar('\n');
return (0);
}
README.md
Create a readme.md file with
echo 'whatever you want to use to describe your work' > README.md
See Part 2: low_level_programming โ 0x01-variables_if_else_while part 2
Show some love by sharing.