As a beginner, it might seem difficult to print a number 100 times without using loop, recursion, and macro expansion. But in this article, we will discuss a simple C program to print a number 100 times without using these concepts.
We can use a technique called "goto" to print the number 100 times. Goto is a control flow statement that transfers the program control to a labeled statement in the same function. In other words, we can use the "goto" statement to jump to a specific line of code in the program.
Here's the C program to print a number 100 times without using loop, recursion, and macro expansion:
#include int main() { int num = 5; //the number to print int i = 1; //initialize the counter //print the number using goto start: printf("%d\n", num); i++; if (i <= 100) //check if the counter is less than or equal to 100 goto start; //jump to the start label return 0; }
In this program, we have initialized two variables: num and i. Num is the number we want to print, and i is the counter that keeps track of the number of times the number has been printed.
We have used the "goto" statement to jump to the label "start" whenever the counter is less than or equal to 100. The label "start" prints the number and increments the counter. This process continues until the counter becomes greater than 100.
This program prints the number 5, which is stored in the variable "num," 100 times without using loop, recursion, and macro expansion.
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.