Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ Challenge: Dubs and Trips

Name: Anonymous 2018-05-24 3:25

Basically a meme variation of FizzBuzz, but not exactly the same.

Write a program that outputs numbers between 1 and 1000 (inclusively). This is like a text board thread.

If it's dubs, instead of the number, print dubs. If trips, print trips. For trips, do NOT also output dubs. Only one or the other. If it's dubs or trips, do not include the number.

Example output:
987
dubs
989
990
991
992
993
994
995
996
997
998
trips


Notice that for 990, it doesn't output dubs, because it only counts for the last digits. And 999 only says trips, not dubs (even though it's also dubs, technically).

Name: Anonymous 2018-05-24 13:17

Compile with :gcc -include "stdio.h" dubs.c
main(i){while(i<999)printf(i%10==i/10%10?i%10==i/100?"trips\n":"dubs\n":"%d\n",++i);}

Name: Anonymous 2018-05-24 13:30

>>8
Some explanation to what is going on for those who don't know C:
1.main defaults to int
2.(i) i defaults to int too, and renames first argument (int argc)
3.argc is 1 by default if no arguments are given.(first argument argv[0] is program name)
4.printf chooses one of three strings, "trips\n":"dubs\n":"%d\n", first two ignore the number (++i) since they lack the decimal output specifier "%d" which is used only if no conditions are met.
5.the condition ternary is left as exercise to the reader.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List