Write a program that prints all the numbers of base 16 in lowercase, followed by a new line.You can only use the putchar function (every other function (printf, puts, etc…) is forbidden)All your code should be in the main functionYou can only use putchar three times in your code
Question
Write a program that prints all the numbers of base 16 in lowercase, followed by a new line.You can only use the putchar function (every other function (printf, puts, etc…) is forbidden)All your code should be in the main functionYou can only use putchar three times in your code
Solution
Here is a simple program in C that meets your requirements:
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
int main(void)
{
char number;
for (number = '0'; number <= '9'; number++)
ft_putchar(number);
for (number = 'a'; number <= 'f'; number++)
ft_putchar(number);
ft_putchar('\n');
return (0);
}
This program uses the write function to implement a custom putchar function, and then uses this function to print all base 16 numbers in lowercase. The main function contains a loop that iterates over the characters '0' to '9' and 'a' to 'f', which represent the numbers of base 16 in lowercase. After printing all these numbers, it prints a newline character.
Similar Questions
Write a program that prints the alphabet in lowercase, and then in uppercase, followed by a new line.You can only use the putchar function (every other function (printf, puts, etc…) is forbidden)All your code should be in the main functionYou can only use putchar three times in your code
Write a program that prints the ASCII alphabet, in lowercase, not followed by a new line.You can only use one print function with string formatYou can only use one loop in your codeYou are not allowed to store characters in a variableYou are not allowed to import any module
Write a C program that prints exactly "Programming is like building a multilingual puzzle, followed by a new line.Use the function putsYou are not allowed to use printfYour program should end with the value 0
Select the correct answerFor single character input and output, Which functions are used?Optionsscanf() and printf()getchar() and putchar()input() and output()None of the given options are correct
Write a C program to print the Pyramid with numbersWrite a program to print a pyramid of numbers separated by spaces for the given number of rows.At the time of execution, the program should print the message on the console as:Enter number of rows : For example, if the user gives the input as:Enter number of rows : 5then the program should print the result as:Enter number of rows : 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.