Jul 25, 2008

Looping Help C

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > C/C++ Programming
Pages: 1, 2

free web hosting

Looping Help C

Larry Rosario
write a program

Reply

osknockout
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.

Reply

hitmanblood
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.

 

 

 


Reply

bhavesh
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

Reply

hitmanblood
Yeah I failed to notice it is C wanted rather then C++.

However you transformed it nicely wink.gif

Reply

pkjm17
very good...well done

Reply

hitmanblood
QUOTE(pkjm17 @ Apr 15 2007, 09:16 PM) *
very good...well done



What do you mean by this????

Reply

rize619
hey what is the logic behind pascal triangle please explain all it to me
and 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.

A
AB
ABC
ABCD
ABCDE

Reply

osknockout
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.

Reply

rize619
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 ...

Reply

Latest Entries

rize619
bro. you are giving spaces by space bar but i need it with the loop
yeah u are right about pascal triangle but i need to generate it using c++ loops structure...



Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Pages: 1, 2

Searching Video's for looping, c
advertisement



Looping Help C



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE