Create a program that will shuffle and display this statements.
Yes it is.
No it's not.
I guess so.
Okay that's all.
What do you think will be the code for this? Im a newbie. Please help
Create a program that will shuffle and display this statements.
Yes it is.
No it's not.
I guess so.
Okay that's all.
What do you think will be the code for this? Im a newbie. Please help
Code:#include <stdlib.h> // rand, srand #include <time.h> // time #include <stdio.h> // puts const unsigned int shuffles[24][4] = { { 0, 1, 2, 3 }, { 0, 1, 3, 2 }, { 0, 2, 1, 3 }, { 0, 2, 3, 1 }, { 0, 3, 1, 2 }, { 0, 3, 2, 1 }, { 1, 0, 2, 3 }, { 1, 0, 3, 2 }, { 1, 2, 0, 3 }, { 1, 2, 3, 0 }, { 1, 3, 0, 2 }, { 1, 3, 2, 0 }, { 2, 0, 1, 3 }, { 2, 0, 3, 1 }, { 2, 1, 0, 3 }, { 2, 1, 3, 0 }, { 2, 3, 0, 1 }, { 2, 3, 1, 0 }, { 3, 0, 1, 2 }, { 3, 0, 2, 1 }, { 3, 1, 0, 2 }, { 3, 1, 2, 0 }, { 3, 2, 0, 1 }, { 3, 2, 1, 0 } }; int main(void) { const char* const phrases[4] = { "Yes it is.", "No it's not.", "I guess so.", "Okay that's all." }; srand(time(NULL)); const unsigned int* const shuffle = shuffles[rand() % 24]; unsigned int i; for( i = 0; i < 4; ++i ) { puts(phrases[shuffle[i]]); } return 0; }
Our goals are clear, tasks are defined! Let's work, comrades! -- Nikita Khrushchev
zub, please stop dumping complete answers with no further explanation, or without the OP making a significant contribution of their own.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
In fact, it is a bit of a joke. If you look closely at the program, you will see that this is a very specific solution. I'm sure, topicstarter needs a more general solution. I'm just tired of the his monotonous questions. Let him disassemble my code. Perhaps he will understand how to formulate the following questions. His problem is not that he does not know the answer. He does not even know what question to ask. I just clarifying it.
Sheckley Robert - Ask a Foolish Question
Our goals are clear, tasks are defined! Let's work, comrades! -- Nikita Khrushchev