473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

printing 0 to 1000 in console screen..

can we write a c code in turboc++(3.0 dos version) which will print the numbers
consequently from 0 to 1000 on the console screen or output screen
provided that we can use only the following system define functions....
1) printf();
2)exit();
3)delay();
4)clrscr();

and it is also provided that the c program will not contain
any loop statement(ie.for loop,while loop,dowhile loop),any ternery operator,
any if else statement,any switch case..........
if someone can solve it then please answer...............
Mar 11 '08 #1
11 1795
sicarie
4,677 Expert Mod 4TB
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

Then when you are ready post a new question in this thread.

MODERATOR
Mar 11 '08 #2
we can,by using recursive function.print the value of variale,increment it,pass to function recursively.
Mar 11 '08 #3
Sick0Fant
121 100+
Use a recursive function.
Mar 11 '08 #4
MACKTEK
40
At first I thought it might be impossible without an "if statement".
But then I remembered &&., and applied recursion using that logic.

I was able to complete the task.
I would be interested in hearing from the experts tho, what tricks they would use. PM if you feel it would reveal too much.
Mar 11 '08 #5
sicarie
4,677 Expert Mod 4TB
A for loop. Why purchase, set up, learn and use the HYDRO SUPER DICER KITCHEN SUPER SET THAT CUTS, FILLETS, AND MINCES ALL AT THE SAME TIME when you can use a regular knife?

Optimization tricks are good to know and implement in the right place, but should not be used in place of good coding practices - it just makes your life harder later.
Mar 11 '08 #6
Banfa
9,065 Expert Mod 8TB
Or you could use the || operator rather than &&

However by far the simplest way is to call to printf 1001 times, once for each line of output or even call printf once with a very long string would do the trick.

You don't appear to have be limited to having to use an integer variable to contain the number!
Mar 11 '08 #7
Banfa
9,065 Expert Mod 8TB
Or you can use a goto statement instead of recursion but the only way I found to exit was to not included stdlib.h so the compiler wasn't aware that exit returns void so I could using it as 1 side of a logical expression :D
Mar 11 '08 #8
Banfa
9,065 Expert Mod 8TB
And there is always the possibility of purposefully creating a SEGFAULT to halt the program hehe although of course that is actually undefined behaviour so not completely guaranteed.
Mar 11 '08 #9
MACKTEK
40
Or you can use a goto statement instead of recursion but the only way I found to exit was to not included stdlib.h so the compiler wasn't aware that exit returns void so I could using it as 1 side of a logical expression :D
Ah, now that is a neat idea... I had the same problem when I tried to do a logical expression with a WriteLine statement, so I just moved it to a different line. But, It would be neat to know how to "trick" the compiler into converting a function that has void as a return type into a function that returns a value.
Mar 11 '08 #10
Banfa
9,065 Expert Mod 8TB
Ah, now that is a neat idea... I had the same problem when I tried to do a logical expression with a WriteLine statement, so I just moved it to a different line. But, It would be neat to know how to "trick" the compiler into converting a function that has void as a return type into a function that returns a value.
OK I MUST caution you on this point. The compiler does not "convert" a void function to a function that returns an value. It just treats it as though it returns a value even though it doesn't.

This is almost certainly undefined behaviour and I would NEVER use such a technique in a serious project or program.

I only suggested it here because this is one of those stupid questions we see educational establishments asking from time to time that imposes a completely unrealistic set of restrictions in an effort to force their students to use some unmentioned technique, presumably one they have just learnt, but since we don't attend their classes we don't have that information.
Mar 11 '08 #11
can anybody show me the code with && or || operators.coz,i didn't get it.
Mar 22 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Totte Karlsson | last post by:
Hi, How can I print to the console without having it scrolling to a new line for each print statement? I want to print a count down in the console, but for each count it scrolls the screen (of...
2
by: Ravi | last post by:
Hi People, I am facing an issue with printing where I have to print receipts of a custom size. Each receipt is about 8 inch by 4inch. I am using window.print(). When a receipt is printed another...
2
by: Brad Pears | last post by:
I have a vb.net 2005 application and am using the print preview screen. This screen has a printer icon on it that the user can use to print the document currently being viewed. It uses the default...
3
by: mrsouthg | last post by:
Hi, I am fairly new to c# .net language and have been using a set of code I was given to learn from. I have found a suitable part which I would like to change, I am however finding it a big hurdle...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.