EvilZone

Programming and Scripting => Other => : kriminal August 24, 2011, 01:12:39 PM

: I need a HELP!!
: kriminal August 24, 2011, 01:12:39 PM
A program that produces a sequence number (in alternate arrangement or in reverse order) using for loop, while loop, and do while loop statements.


example output:
5,1,4,2,3,3,2,4,1,5


Kindly help me with this please!
I'm having a self study here...
: Re: I need a HELP!!
: ca0s August 24, 2011, 01:39:05 PM
In C:
:
#include <stdio.h>
int main()
{
    int max=5, i;
    for(i=0; i<max; i++) printf("%i, %i,", max-i, i+1);
    return 0;
}

Not tested it, no compiler available, but I think it should work...
: Re: I need a HELP!!
: kriminal September 01, 2011, 11:49:21 AM
thank you for that but maybe there some mistake because only X1 shows in the prompt without stopping... can u fix that problem?? PLEASE!!!
: Re: I need a HELP!!
: ca0s September 01, 2011, 12:24:27 PM
No mistake. You asked for an algorythm to generate that input, and it does it right. Execute it from a shell and see it.
: Re: I need a HELP!!
: kriminal September 01, 2011, 10:48:53 PM


#include <iostream.h>
int main()
{
   int max=2, i;
   for(i=0; i<max; i++)
      cout<<"5,1,4,2,3 ", max-i, i+1;
   return 0;
}
Thank you sir, your code is great help for me.


The output that is 5,1,4,2,3,5,1,4,2,3


How can I make that output  in this form: 5,1,4,2,3,3,2,4,1,5
: Re: I need a HELP!!
: ca0s September 01, 2011, 11:16:49 PM
What do you want to do with that code? What you asked for in the first post has been answered.
: Re: I need a HELP!!
: kriminal September 01, 2011, 11:45:35 PM
I just want to know if my code is correct.
: Re: I need a HELP!!
: ca0s September 02, 2011, 01:37:08 AM
Don't know C++ but

:
#include <iostream.h>
int main()
{
   int max=5, i;
   for(i=0; i<max; i++)
      cout<<max-i, ",",  i+1, ",";
   return 0;
}
I think is what you want.
: Re: I need a HELP!!
: xzid September 02, 2011, 05:53:45 AM
:
#include <iostream>
int main()
{
   int max=5, i;
   for(i=0; i<max; i++)
      std::cout << (max-i) << "," << (i+1) << ",";
   return 0;
}

<iostream>, drop .h.. C++ also needs to know what "cout" is. and "," won't work as you think in this situation, you need <<. needless to say printf is alot less ugly.

OP you seem to be stuck between 2 languages, pick one. I'd recommend C. Also you've been working on this for more than a week, seriously google how to code. ca0s gave you algo, the only thing left for you to do is implement it in your language.

: Re: I need a HELP!!
: kriminal September 02, 2011, 06:01:34 AM
There's missing sir.
The output of your code is 54321
The output should be like this 5,4,3,2,1,1,2,3,4,5
Can your show me how? please!
: Re: I need a HELP!!
: xzid September 02, 2011, 06:07:25 AM
There's missing sir.
The output of your code is 54321
The output should be like this 5,4,3,2,1,1,2,3,4,5
Can your show me how? please!

I believe you are mistaken sir. Don't change it though(all these quotes are you):

The output should be like this 5,4,3,2,1,1,2,3,4,5
How can I make that output  in this form: 5,1,4,2,3,3,2,4,1,5
example output:
5,1,4,2,3,3,2,4,1,5

The code matches #2 & #3, and yeah it works.


:
PS K:\>cat test.cpp
#include <iostream>
int main()
{
   int max=5, i;
   for(i=0; i<max; i++)
      std::cout << (max-i) << "," << (i+1) << ",";
   return 0;
}
PS K:\>g++ -o test test.cpp
PS K:\>./test; "`n"
5,1,4,2,3,3,2,4,1,5,

PS K:\>
: Re: I need a HELP!!
: kriminal September 02, 2011, 06:32:39 AM
It's ok now sir. Thank you so much!!!
Can you be my teacher? If you don't mind. Because I want to know more about C++ programming.
: Re: I need a HELP!!
: xzid September 02, 2011, 06:35:07 AM
It's ok now sir. Thank you so much!!!
Can you be my teacher? If you don't mind. Because I want to know more about C++ programming.

No. Although a simple google search will bring up hundreds of c++ tutorials... Pick one.
: Re: I need a HELP!!
: kriminal September 02, 2011, 06:50:22 AM
Okay! Thank you so much for the help.
Can I ask your help again when I have problems regarding C++ programming?
: Re: I need a HELP!!
: xzid September 02, 2011, 07:00:52 AM
Just post a thread, I'm sure someone will help. Don't go overboard with it though, you need to put alot of effort into getting it to work before asking others for help.

edit: I should also point out that I, like ca0s, am a C programmer not C++.
: Re: I need a HELP!!
: kriminal September 03, 2011, 07:26:24 AM
Is C and C++ programming have a big difference?
: Re: I need a HELP!!
: gh0st September 03, 2011, 08:25:45 AM
It was developed by Bjarne Stroustrup starting in 1979 at Bell Labs as an enhancement to the C language. Originally named C with Classes, the language was later renamed C++ in 1983.
: Re: I need a HELP!!
: xzid September 03, 2011, 09:22:36 AM
It was developed by Bjarne Stroustrup starting in 1979 at Bell Labs as an enhancement to the C language. Originally named C with Classes, the language was later renamed C++ in 1983.

Oh that wiki! What you posted is completely misleading gh0st. Although as long as we're referring to the C++ wiki page, this quote is just perfect:

Richard Stallman criticizes C++ for having ambiguous grammar and "gratuitous, trivial, incompatibilities with C (...) that are of no great benefit".

Linus Torvalds has said, "C++ is a horrible language. It's made more horrible by the fact that a lot of substandard programmers use it".

Is C and C++ programming have a big difference?

A huge difference.

C++ provides alot of additional features, none of which help the C language. You learn alot more stuff, but none of it seems to help. Not once have I programmed C and thought: "You know what's missing here? Classes, templates and overloaded functions!!!".

C is used for low-level, if you want to do kernel, network, system programming(Security/Hacking falls under this category as well)... There is no other language. The extent of OOP are functions pointers(example of something that looks OOP is LKM programming). C forces you to know exactly what your program is doing.. Say you wanna use the IP protocol, well there are no shortcuts... refer to the rfc. This is also the reason every C programmer will eventually move on to ASM, to learn exactly what his C program(and his computer) is doing. C can do pretty much everything, although on things like GUI will be a headache more than anything.

C++ has it uses as well, say GUI, game programming, large applications with 101 different things built into it. If this is what you seek, java might be a better way to go.
: Re: I need a HELP!!
: kriminal September 04, 2011, 07:41:47 PM
I don't have an idea about this problem. Can anyone who can teach me how to solve this problem in C++ using for loop..


Write a program to scan a number n and then output the sum of the squares from 1 to n. Thus, if the input is 4, the output should be 30 because:

            12 + 22 + 32 + 42 = 1+4+9+16 = 30
: Re: I need a HELP!!
: kriminal September 04, 2011, 08:59:05 PM

This is my idea. Not yet compiled.