Larry Rosario 0 Report post Posted March 22, 2007 (edited) write a program Edited October 23, 2007 by Larry Rosario (see edit history) Share this post Link to post Share on other sites
osknockout 0 Report post Posted March 24, 2007 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
hitmanblood 0 Report post Posted April 15, 2007 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
bhavesh 0 Report post Posted April 15, 2007 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
hitmanblood 0 Report post Posted April 15, 2007 Yeah I failed to notice it is C wanted rather then C++.However you transformed it nicely Share this post Link to post Share on other sites
pkjm17 0 Report post Posted April 15, 2007 very good...well done Share this post Link to post Share on other sites
hitmanblood 0 Report post Posted April 15, 2007 very good...well done What do you mean by this???? Share this post Link to post Share on other sites
rize619 0 Report post Posted July 1, 2007 (edited) 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 July 1, 2007 by rize619 (see edit history) Share this post Link to post Share on other sites
osknockout 0 Report post Posted July 1, 2007 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
rize619 0 Report post Posted July 2, 2007 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
osknockout 0 Report post Posted July 2, 2007 @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
rize619 0 Report post Posted July 6, 2007 bro. you are giving spaces by space bar but i need it with the loopyeah u are right about pascal triangle but i need to generate it using c++ loops structure... Share this post Link to post Share on other sites