Hi,
If any one know the answer for the following questions
Write a C++ program without using any loop (if, for, while etc) to print numbers from 1 to 100
8 15952
Hi,
If any one know the answer for the following questions
Write a C++ program without using any loop (if, for, while etc) to print numbers from 1 to 100
That's one hell of a cout statement.
If I were you i would go back with a program that printed
"numbers from 1 to 100"
(though that would probably not be beneficial to your grade ;) )
Hi,
If any one know the answer for the following questions
Write a C++ program without using any loop (if, for, while etc) to print numbers from 1 to 100
void main()
{ int count=1
LABEL: cout<<count<<',';
count++;
if(count<=100) goto LABEL;
}
void main()
{ int count=1
LABEL: cout<<count<<',';
count++;
if(count<=100) goto LABEL;
}
That's still an 'if' statement.
- int main() {
-
-
cout << 1 << endl;
-
cout << 2 << endl;
-
cout << 3 << endl;
-
cout << 4 << endl;
-
cout << 5 << endl;
-
cout << 6 << endl;
-
cout << 7 << endl;
-
// ...
-
cout << 100 << endl;
-
system("PAUSE");
-
return 0;
-
}
-
How's this? -
#include <stdlib.h>
-
#include <stdio.h>
-
-
void
-
printnum(int n)
-
{
-
printf("%d\n", n);
-
}
-
-
void
-
done(int n)
-
{
-
exit(0);
-
}
-
-
int
-
main(void)
-
{
-
int n = 1, i;
-
void (*f[2])(int);
-
f[0] = &done;
-
f[1] = &printnum;
-
-
LABLE:
-
i = n <= 100;
-
(*f[i])(n);
-
n++;
-
goto LABLE;
-
-
return 1;
-
}
-
That has to be the dumbest C assignment I've ever seen whatever happened to Print "Hello World"? Why wouldn't you use a loop for that?
Heh, I'm an idiot, it can also be done recursively to avoid anything like a loop. -
#include <stdlib.h>
-
#include <stdio.h>
-
-
void (*f[2])(int);
-
-
void
-
printnum(int n)
-
{
-
printf("%d\n", n);
-
int i;
-
i = ++n <= 100;
-
(*f[i])(n);
-
}
-
-
void
-
done(int n)
-
{
-
exit(0);
-
}
-
-
int
-
main(void)
-
{
-
int n = 1;
-
-
f[0] = &done;
-
f[1] = &printnum;
-
-
printnum(n);
-
-
return 1;
-
}
-
Actually, I'd go for the ternary operator ?:
var ? var<100 : print var++
(the above is pseudocode)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Martin Bless |
last post by:
Why can't we have an additional 'print' statement, that behaves
exactly like 'print' but doesn't insert that damn blank between two
arguments?
Could be called 'printn' or 'prin1' or 'prinn'...
|
by: Marcin Ciura |
last post by:
Here is a pre-PEP about print that I wrote recently.
Please let me know what is the community's opinion on it.
Cheers,
Marcin
PEP: XXX
Title: Print Without Intervening Space
Version:...
|
by: SQL |
last post by:
The trick is to use a pivot table
Check out the code here
http://sqlservercode.blogspot.com/2005/09/fast-date-ranges-without-loops-in-sql.html
|
by: Saurabh Saxena |
last post by:
can we write the program to write no 1 to n without using
switch,do,while,for,goto,if and conditional operator where n will be
input by user.
|
by: bafidi |
last post by:
i want links to read where it teachs me to print without cristal reports
please help
|
by: Mike |
last post by:
Hi,
Is there anyway to print from VB.NET or C# and bypass the printer dialog
box?
Thanks
Mike
|
by: JMH |
last post by:
Hi,
I've seen plenty of examples of printing a windows form without previewing
the data, but I was wondering if anyone knew of a way to do this on a webpage?
I have a webform, reportviewer...
|
by: Alba López |
last post by:
Hi, I want to print a webform directly to the default printer, without
showing the user the print dialog box.
I used to do it with window.open and it worked as I wanted to, but after
installing...
|
by: engloon |
last post by:
Hi guys.
I found this code that read a file then print out.
The problem that I'm facing is, I have a lot of files to be printed, so I would like to print without showing the print property menu....
|
by: Pheddy |
last post by:
Hi all..
Does anybody knows if it is possible to create a page that IE will print WITHOUT the url information in the bottom of the page?
Thanks.
Frederik
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |