Question:
How would you write a C program to print 1 to 100 without loop, recursion, or goto?
Solution:
#include<stdio.h>
void hundred() { static int i=1; printf("%d\n",i++); }
void twenty(){ hundred(),hundred(),hundred(),hundred(),hundred(); }
void four() { twenty(),twenty(),twenty(),twenty(),twenty(); }
int main()
{
four(),four(),four(),four();
}
How would you write a C program to print 1 to 100 without loop, recursion, or goto?
Solution:
#include<stdio.h>
void hundred() { static int i=1; printf("%d\n",i++); }
void twenty(){ hundred(),hundred(),hundred(),hundred(),hundred(); }
void four() { twenty(),twenty(),twenty(),twenty(),twenty(); }
int main()
{
four(),four(),four(),four();
}
0 comments:
Post a Comment