EvilZone
Programming and Scripting => Other => : 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...
-
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...
-
thank you for that but maybe there some mistake because only X1 shows in the prompt without stopping... can u fix that problem?? PLEASE!!!
-
No mistake. You asked for an algorythm to generate that input, and it does it right. Execute it from a shell and see it.
-
#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
-
What do you want to do with that code? What you asked for in the first post has been answered.
-
I just want to know if my code is correct.
-
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.
-
#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.
-
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!
-
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:\>
-
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.
-
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.
-
Okay! Thank you so much for the help.
Can I ask your help again when I have problems regarding C++ programming?
-
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++.
-
Is C and C++ programming have a big difference?
-
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.
-
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.
-
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
-
- #include <iostream.h>
- int main()
- {
- int n, i, sum;
-
- cout << "Enter a value for n: ";
- cin >> n;
- sum = 0;
- i = 1;
- do
- {
- sum += i*i;
- i++;
- }while (i <= n);
- cout << "The sum of the first " << n
- << " numbers is " << sum << endl;
-
- return 0;
- }
This is my idea. Not yet compiled.