I was asked to submit atleast 5 solutions for the following problem:
By Replacing/Adding or deleting only one character from the following
code snippet, make it print tttttttttttttttttttt (20 times)
#include<stdio.h>
int main()
{
int k, j=20;
for(k=0;k<j;k--)
printf("t);
printf("\n");
return 0;
}
I came up with 3 solutions which were
1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)
2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)
3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)
Can anyone suggest me 2 more solutions? 11 1856
Romram <sa***********@gmail.com> wrote: I was asked to submit atleast 5 solutions for the following problem:
By Replacing/Adding or deleting only one character from the following code snippet, make it print tttttttttttttttttttt (20 times)
#include<stdio.h>
int main() { int k, j=20; for(k=0;k<j;k--) printf("t); printf("\n"); return 0; }
I assume you forget the closing quote in the first printf(). Please make
sure that the code you post actually is correct and compiles.
1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)
2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)
3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)
Can anyone suggest me 2 more solutions?
instead of for(k=0;k<j;k--) write for(k=0;k<j;j-- )
instead of for(k=0;k<j;k--) write for(k=0;k<j;j-- )
et cetera. If this is not considered a correct answer, the question
should have been more precise.
--
:wq
^X^Cy^K^X^C^C^C^C Can anyone suggest me 2 more solutions?
instead of for(k=0;k<j;k--) write for(k=0;k<j;j-- ) instead of for(k=0;k<j;k--) write for(k=0;k<j;j-- )
et cetera. If this is not considered a correct answer, the question should have been more precise.
-- :wq ^X^Cy^K^X^C^C^C^C
I meant 5 different or unique solutions. Does it make the question
clear now?
Ico <us****@zevv.nl> wrote: Romram <sa***********@gmail.com> wrote: I was asked to submit atleast 5 solutions for the following problem:
By Replacing/Adding or deleting only one character from the following code snippet, make it print tttttttttttttttttttt (20 times)
#include<stdio.h>
int main() { int k, j=20; for(k=0;k<j;k--) printf("t); printf("\n"); return 0; }
I assume you forget the closing quote in the first printf(). Please make sure that the code you post actually is correct and compiles.
1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)
2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)
3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)
Can anyone suggest me 2 more solutions?
instead of for(k=0;k<j;k--) write for(k=0;k<j;j-- ) instead of for(k=0;k<j;k--) write for(k=0;k<j;j-- )
Ehm, no those are wrong ofcourse, I changed *and* inserted, which is
against the rules. I should sit on my hands before I type.
--
:wq
^X^Cy^K^X^C^C^C^C
Romram <sa***********@gmail.com> wrote: I was asked to submit atleast 5 solutions for the following problem:
By Replacing/Adding or deleting only one character from the following code snippet, make it print tttttttttttttttttttt (20 times)
#include<stdio.h>
int main() { int k, j=20; for(k=0;k<j;k--) printf("t); printf("\n"); return 0; }
I came up with 3 solutions which were
1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--) 2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--) 3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)
Can anyone suggest me 2 more solutions?
I have reason to believe you have already found the only three possible
solutions. I couldn't think of any more than the ones you already
stated, so I have just tried a brute-force search of all possible
replaces/additions/deletions of all possible characters at all possible
locations.
I'm interested in any other solutions that I might have missed.
Ico
--
:wq
^X^Cy^K^X^C^C^C^C
Romram wrote: I was asked to submit atleast 5 solutions for the following problem:
By Replacing/Adding or deleting only one character from the following code snippet, make it print tttttttttttttttttttt (20 times)
#include<stdio.h>
int main() { int k, j=20; for(k=0;k<j;k--) printf("t); printf("\n"); return 0; }
I came up with 3 solutions which were
1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)
2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)
3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)
Can anyone suggest me 2 more solutions?
Clearly some sort of homework. The canonical for loop ..
for (k = 0; k < j; ++k)
... otherwise the loop almost infinite. The snippet is broken in at least
two places and cannot be fixed with one change (as far as I can tell).
Please compile these things into small programs before posting here.
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Ico wrote: Romram <sa***********@gmail.com> wrote: I was asked to submit atleast 5 solutions for the following problem:
By Replacing/Adding or deleting only one character from the following code snippet, make it print tttttttttttttttttttt (20 times)
#include<stdio.h>
int main() { int k, j=20; for(k=0;k<j;k--) printf("t); printf("\n"); return 0; }
I came up with 3 solutions which were
1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--) 2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--) 3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)
Can anyone suggest me 2 more solutions?
I have reason to believe you have already found the only three possible solutions. I couldn't think of any more than the ones you already stated, so I have just tried a brute-force search of all possible replaces/additions/deletions of all possible characters at all possible locations.
I'm interested in any other solutions that I might have missed.
add a single `-' to for(k=0;k<j;k--): for(k=0;-k<j;k--)
________^________
--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Pedro Graca <he****@dodgeit.com> wrote: Ico wrote: Romram <sa***********@gmail.com> wrote: I was asked to submit atleast 5 solutions for the following problem:
By Replacing/Adding or deleting only one character from the following code snippet, make it print tttttttttttttttttttt (20 times)
#include<stdio.h>
int main() { int k, j=20; for(k=0;k<j;k--) printf("t); printf("\n"); return 0; }
I came up with 3 solutions which were
1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--) 2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--) 3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)
Can anyone suggest me 2 more solutions?
I have reason to believe you have already found the only three possible solutions. I couldn't think of any more than the ones you already stated, so I have just tried a brute-force search of all possible replaces/additions/deletions of all possible characters at all possible locations.
I'm interested in any other solutions that I might have missed.
add a single `-' to for(k=0;k<j;k--): for(k=0;-k<j;k--) ________^________
Is that not the same as OP's solution #2 ?
--
:wq
^X^Cy^K^X^C^C^C^C
Ico wrote: Romram <sa***********@gmail.com> wrote: I was asked to submit atleast 5 solutions for the following problem:
By Replacing/Adding or deleting only one character from the following code snippet, make it print tttttttttttttttttttt (20 times)
#include<stdio.h>
int main() { int k, j=20; for(k=0;k<j;k--) printf("t); printf("\n"); return 0; }
I came up with 3 solutions which were
1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--) 2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--) 3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)
Can anyone suggest me 2 more solutions?
I have reason to believe you have already found the only three possible solutions. I couldn't think of any more than the ones you already stated, so I have just tried a brute-force search of all possible replaces/additions/deletions of all possible characters at all possible locations.
I'm interested in any other solutions that I might have missed.
My last post was a repeated solution. Sorry.
If you don't mind UB (decrementing k past INT_MIN) or using an
unprototyped function or waiting for the program to go through all the
negative values of the int type ...
instead of printf("t"); write pruntf("t"); and link with a library that
defines
int pruntf(char const * t) {
static int n = 20;
if (n) {
--n;
printf("%s", t);
}
return 0;
}
--
If you're posting through Google read <http://cfaj.freeshell.org/google> instead of printf("t"); write pruntf("t"); and link with a library that defines
int pruntf(char const * t) { static int n = 20; if (n) { --n; printf("%s", t); } return 0; }
You can change only one character in the code..... adding a library is
way out of the question..
Romram <sa***********@gmail.com> wrote: I was asked to submit atleast 5 solutions for the following problem:
By Replacing/Adding or deleting only one character from the following code snippet, make it print tttttttttttttttttttt (20 times)
#include<stdio.h>
int main() { int k, j=20; for(k=0;k<j;k--) printf("t); printf("\n"); return 0; }
I came up with 3 solutions which were
1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--) 2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--) 3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)
Can anyone suggest me 2 more solutions?
It's been a few days now, did you found any alternatives yet ?
Ico
--
:wq
^X^Cy^K^X^C^C^C^C It's been a few days now, did you found any alternatives yet ?
NO This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: mike420 |
last post by:
In the context of LATEX, some Pythonista asked what the big
successes of Lisp were. I think there were at least three *big*
successes.
a. orbitz.com web site uses Lisp for algorithms, etc.
b....
|
by: Rabbit63 |
last post by:
Hi:
I want to show a set of records in the database table on the clicnt browser.
I have two ways to do this (writen in JScript):
1.The first way is:
<%
var sql = "select firstname from...
|
by: Martin |
last post by:
I am reading through Koenig and Moo's "Accelerated C++" and attempting the
exercises. Are there any sample solutions somewhere? It's all very well me
doing a solution, which seems to work, but for...
|
by: Bob Morvay |
last post by:
I am interested in any .NET enabled portal solutions that
are in the same class as the J2EE BEA Weblogic portal
solution. Can anyone point me to articles comparing the
available portal solutions...
|
by: Dmitry Shafranov |
last post by:
Hi. Does anybody know a website with solutions to 3rd edition of Bjarne
Stroustrup's *The C++ Programming Language*. I have already purchased
David Vandevoorde's *C++ Solutions,* but unfortunately...
|
by: Mike MacSween |
last post by:
S**t for brains strikes again!
Why did I do that? When I met the clients and at some point they vaguely
asked whether eventually would it be possible to have some people who could
read the data...
|
by: Jerad Rose |
last post by:
This is regarding Visual Studio 2003 (framework 1.1). We have several
projects/libraries. Of course, many of these reference each other. If we
only had one solution, we would simply add all of...
|
by: Sky |
last post by:
I have been looking for a more powerful version of GetType(string) that will
find the Type no matter what, and will work even if only supplied
"{TypeName}", not the full "{TypeName},{AssemblyName}"...
|
by: coolcatjon |
last post by:
Hey guys-
I've decided to learn me some C, as any hacker must :)
So I've got a C compiler handy, and I've downloaded the book by
Kernergan and Richie that was recommended to me...
One bad...
|
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...
|
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...
|
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...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |