Write a short program that takes an integer value (call it n) from the user and prints out a triangle composed of O and X characters.
For example, if the user enters 3 as the input, your program should print out:
O
OX
O X O
If the user enters 5 as the input, your program should print out:
O
O X
O X O
O X O X
O X O X O

Sorry I couldn't give you some code that I have use to attempt this question. But I have no idea how to do this. Thanks a lot in advance :)

Recommended Answers

All 5 Replies

yeah i know how to do this actually
Sorry i couldn't give you some code that i have use to attempt this question. But i have no idea why I should get yoour a grade when i do all the work.
You're welcome in advance :)
(nested)

yeah i know how to do this actually
Sorry i couldn't give you some code that i have use to attempt this question. But i have no idea why I should get yoour a grade when i do all the work.
You're welcome in advance :)
(nested)

Sorry I didn't mention, its just a practice exercise. All our marked worked is done in class to prevent problems like the one you just implied :P

lol
well i dont think anyone here is going to give the code so i hope you're right
but you need to use nested for loops

lol
well i dont think anyone here is going to give the code so i hope you're right
but you need to use nested for loops

I don't really want someone to post a whole, that would take forever lol I just need some guidance.

Okay I've managed to do this but I need to know how to get it to print off the result in "X"'s and "O"'s

#include <iostream>
using namespace std;

int main(){
int n;
cout<<"Enter an integer"; 
cin>>n;
for(int row=1;row<=n;row++){
     for(int col=1;col<=row;col++);
		  cout<<n+1-row;
          
     cout<<endl;
}


system ("pause");
	return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.