Jump to content
xisto Community
Sign in to follow this  
Larry Rosario

Looping Help C

Recommended Posts

Heh, sounds like hmwk to me.You'd probably want to do two while loops - one nested in the other - one for determining how many numbers to display, and the second displaying the numbers. Both of your outputs display numbers in increasing order, so you'd probably just reverse the increment/decrement in the outer loop and change the index variable to get the other.-Just an idea, you probably should look through tutorials and such. They normally cover this stuff in the example section. It isn't that hard to transcribe it for your case.

Share this post


Link to post
Share on other sites

This program of yours is probably not needed anymore but I have decided to write it if you care for it still. Here comes the code.// Programs makes interesting output some sort of triangle with numbers.// HitmanBlood#include<iostream>using namespace std;int main(){ for(int j = -1; j <= 5; j++){ //First loop coordinates the raws for(int k = j + 1; k <= 5; k++){ // Cordinates this second loop for columns cout << k; } cout << endl; // Transfer to the new line that is new raw } //Second output for(int j = 6; j >= 1; j--){ // This loop is again coordinating raws for(int k = j - 1; k <= 5; k++){ // Second loop which is coordinating columns. cout << k; } cout << endl; // Transfer to the new line that is new raw } system("pause"); // If you are using linux just delete or comment this line }You see it is simple as that.

Share this post


Link to post
Share on other sites

Its is soooooooooooooooo simple.... But Mr. hitmanblood made it in C++ and you said in C so take it in C.......

 

void main()

{

int i,j;

clrscr();

printf("a.\n\n");

for(i=-1; i<=5; i++)

{

for(j=i+1; j<=5; j++)

{

printf("%d",j);

}

printf("\n");

}

printf("\nb.\n\n");

for(i=6; i>=1; i--)

{

for(j = i-1; j<=5; j++)

{

printf("%d",j);

}

printf("\n");

}

printf("\n\nplease help ...\n");

}

 

By:Bhavesh

Share this post


Link to post
Share on other sites

hey what is the logic behind pascal triangle please explain all it to meand also explain the following program code to me as well(using loops)1.*********S PACE**S PACE**S PACE*********(as spaces dont work here so i write space to fill the space)2.AABABCABCDABCDE

Edited by rize619 (see edit history)

Share this post


Link to post
Share on other sites

What do Pascal triangles have anything to do with the previous posts? Wikipedia Pascal's Triangle if you really want to know.#1 - are there actual newlines or are there just asterisks, three spaces, and more asterisks?#2 - Here's one way using alphanumerics: take any of the programs already given in code, remove the spaces, and then use a (char) adjusting for the ASCII table. You'd probably add 64 to each index, assuming A=1, B=2, etc.

Share this post


Link to post
Share on other sites

i really dont get you osknockout what you are talking about i need help with this LOOP and i cannot understand ya single word.... i want to program it in C++ ...a programmer known well what is pascal triangle ...

Share this post


Link to post
Share on other sites

@rize619: Yeah, I'm talking about the same LOOPS. I couldn't tell what your first program was doing at first though, so that question may have been cryptic, but if you're programming -competently- in C++, how do you not understand what I'm talking about?

 

Anyway, for #1:

int i;while(i!=7){ std::cout << "*"; i++;}i = 0;while(i!=3){ std::cout << "\n" << "* *"; i++;}i = 0;std::cout << "\n";while(i!=7){ std::cout << "*"; i++;}
There. So simple a n00b can understand it. I'm not going to waste my time running it to see if it works, Just add the headers, and you should be able to modify it if something's wrong.

 

For #2: Copy-and-paste ANY of the code examples given for the 1 1-2 1-2-3 stuff. Then, treat the integers as characters, it's called typecasting, that's what the (char) means. Add 64 so that it displays in ASCII properly, and you're done. If you think I'm wrong, try coding it and play with the constant as you wish.

If you don't understand this still, please go back slowly and review the stuff you don't know, this should all be standard stuff though. The only place where I can see confusion is where I requested that the spaces be removed; I was looking at the original post which has spaces, it seems the c++ code doesn't.

 

Alright, apparently you don't know what I'm talking about. Wikipedia time:

from Pascal's Triangle: In mathematics, Pascal's triangle is a geometric arrangement of the binomial coefficients in a triangle.

from Binomial Coefficients: the binomial coefficient of the natural number n and the integer k is the number of combinations that exist

Ok, given the above definitions, please tell me what on earth pascal's triangle had to do with the previous posts.

And you're right, a programmer should know what Pascal's triangle is well... but then that begs the question, WHY are you asking behind it's logic then?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.