C++ :: Program To Display N Depth Pyramid

Feb 21, 2013

Write a program that displays n depth * pyramid.

For example,Input: 4
Output:
*
***
*****
*******

This is what i have so far but it not giving me what i want.

#include <iostream>
using namespace std;
int main() {
int star;
int count=1;
cout<<"Enter the number: ";
cin>>star;

[Code] ....

View 1 Replies


ADVERTISEMENT

C# :: Upper Pyramid Is Working Fine But Lower Pyramid Executes Infinite

Feb 10, 2015

I need to print like below pattern.

1
121
12321
1234321
123454321
1234321
12321
121
1

I got the upper pattern but below pattern is not working it executes infinte loop, how to reslove this.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ro {
class ro {
static void Main(string[] args) {
int numberoflayer = 5, Space, Number;

[Code] ....

View 1 Replies View Related

C++ :: Depth And Breadth First Search Program

Mar 15, 2014

I am not sure how to have to user input numbers into a tree and to have it print out the steps it takes to reach the goal

Header File

#include <iostream>
#include <stack>
using namespace std;
bool recursive_depth(int);
bool is_goal(int);
void input_tree();
void print_tree();

[Code] .....

View 4 Replies View Related

C++ :: Star Pyramid Program - Adding Stars?

Sep 13, 2013

I have written a star pyramid program, it adds two stars at a time but I want to rewrite the program so the stars double each time.

#include<iostream>
using namespace std;
int main() {
int a = 0, b = 8;
for (int c = 1; c < 10; c++) {
for (int space = b; space > 0; space--)

[Code] ...

View 1 Replies View Related

Visual C++ :: Custom Pyramid Drawing Program

Jul 6, 2014

I am trying to figure out how to create a program that will draw a triangle using *'s with a base the has a user-inputted number of *'s like so:

*
***
*****

It needs to take a user inputted number and draw a pyramid like the above pyramid with the number of *'s in the base matching the user inputted number (i.e., user enters 10, so the triangle has 10 *'s in the base). I figured it would be best to first create a loop to draw out the correct number of *'s before trying to create another loop to draw out the correct number of spaces, to properly align the *'s into a triangle shape.

int width = 0;
int height = 0;
int i = 0;
int leafWidth = 0;

[Code] .....

View 7 Replies View Related

C++ :: Displaying Inverted Pyramid

Oct 7, 2013

The user will enter the number of '*'s on the 1st row (ntop) and then the number of rows forming the trapezoid (nrows). (using <iostream>, cout)

For instance, an inverted trapezoid with 7 '*"s in the 1st row and 3 rows forming the inverted trapezoid looks like:

for (i = nrows; i >= 1; i--) {
for (j = 0; j >= nrows; j++) {
cout << " ";
} for (k=ntop; k >= 2; k--) {
cout << "*";
} }

The output is just blank as of now.

View 3 Replies View Related

C++ :: How To Make Inverted Pyramid

Oct 4, 2013

I am new to C++ and I want to make an inverted pyramid so it follows the form of:

54321
x432x
xx3xx

or:

7654321
x65432x
xx543xx
xxx4xxx

The goal is to make it look like that pattern. The x's denote spaces. This is only for integers under 10.

#include<iostream>
using namespace std;
int main() {
int n,i,j;
cout << "Enter a positive odd number: ";
cin >> n;

[Code] ....

I am not sure how to add the spaces or make it subtract like the pattern.

View 7 Replies View Related

C/C++ :: ASCII Art For Different Triangles And Pyramid

Mar 15, 2015

I have to Write a program to produce that makes four triangles and a pyramid. I have to ask the user they height of the triangle and prevent the user from entering a height any larger than 25. It should look like this.

Enter the height of your triangle/pyramid: 3

***
**
*

*
**
***

*
**
***

***
**
*

*
***
*****

im having tourble with 3 and 4th and also pyramid.

HERES WHAT I HAVE SO FAR.

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main () {
int input = 0;
cout << "Please enter the height of your triangle/pyramid: ";

[Code] .....

View 2 Replies View Related

C++ :: Pyramid Of Stars With Spaces

Mar 21, 2013

How to solve this (for cycle)?

View 12 Replies View Related

C# :: Logic For Building Numbers Pyramid?

Jan 7, 2012

Code:
1
121
12321
1234321
123454321 EDIT:
the above pyramid looks like a doom.i.e 1-5 will be in center.1-4(L)1-3(L)1-2(L)1(L) similarly 1-4(R) 1-3(R) 1-2(R) 1(R)

I'm partly successful in building the requirement of the program.but cant able to think the logic for the other half. how can i proceed.below is the code written in c#.

Code:
for (int i = 1; i <= 5; i++)
{
//int l = 1;

[Code]....

View 3 Replies View Related

C :: Depth-first Search Of A Graph

May 18, 2013

You have to implement a data structure to represent graphs,directed or undirected,that tries to avoid the wasted space in the representation of a graph with adjacency matrix and the difficulty of searching the edges with adjacency list representation.We consider that the vertices are numbered from 1 to nverts and the exit degree of each vertex is at most MAXDEG. If deg[i] is the exit degree of the vertex i then the neighbors of the vertex i can be saved at the matrix edge[i][j], 1<=j<=deg[i].

Write a program that reads the datas from a file: if the graph is directed or undirected(1 or 0), the number of vertices (nverts),the number of edges (nedges) and the first and the last vertex of each edge.Write the function dfs that, with argument the data structure that you implemented before for the representation of a graph, prints the edges by the depth-first search of a graph. What I've done so far is: I wrote a program that reads these information from a file, calculates the exit degree of each vertex and creates the matrix edge[i][j]. What data structure do I have to implement???

View 1 Replies View Related

C :: Depth First Search Implementation

Mar 12, 2013

I'm having problems with implementing depth first search.

Code:
6 10 //6vertices 10edges
0 2 //vertex and its adjacent vertex
1 0
1 2
2 3
2 4
3 1
4 1
4 3
4 5
5 3

Output to terminal: 0 2 3 1 4 5
but it should be: 0 2 4 5 3 1

Here's my code:

#include<stdio.h>
#include<assert.h>
/* maxVertices represents maximum number of vertices that can be present in the graph. */
#define maxVertices 100
void Dfs(int graph[][maxVertices], int *size, int presentVertex,int *visited)

[Code] ....

View 1 Replies View Related

C++ ::  Depth First Search - Won't Compile

Jan 13, 2013

I've been trying to implement this Depth First Search graph algorithm using STL, and I get some error from Visual C++ 2012 at compilation.

The code is:

#include <fstream>
#include <stack>
#include <vector>
#include <algorithm>

[Code].....

And the error says something like this:

Debug Assertion Failed!

Program: C:WindowsSYSTEM32MSVCP110D.dll
File: d:...vs2012vcincludedeque
Line: 1497

Expression: deque empty before pop

View 1 Replies View Related

C++ :: Height Or Depth Of Binary Tree

Feb 23, 2014

I'm in interested to know what will be the height of binary tree with say 5 nodes (consider it balanced) is it 2 or 3?

9
/
5 13
/
3 7

and for following tree also:

2
/
7 5
/
2 6 9
/ /
5 11 4

is it 3 or 4?

i'm asking because, not able to find correct/one answer.

the algorithm i find is:

depth(struct tree*t) {
if ( t == NULL) return 0;
return max( depth(tree->left), depth(tree->right) ) + 1;
}

According to it, ans for second will be 4

But as per image on wikipedia [URL] .... the ans is 3

View 6 Replies View Related

C++ :: Calculating depth Of Binary Tree

Apr 1, 2013

i have come across this code for calculating the depth of a binary tree.

int maxDepth(Node *&temp) {
if(temp == NULL)
return 0;
else {
int lchild = maxDepth(temp->left);
int rchild = maxDepth(temp->right);

[Code] ....

In these recursive calls i am really clue less about how the statements i numbered from 1 to 4 would be executed...in every recursive call...???

Lets temp has left depth of 3 and right depth of 100 then...in last 97 recursive calls max(temp->left) would be doing...????? how these recursive mechanism work here... I want to know specifically how these left node and right node recursive calls are co-ordinating with each other????

View 2 Replies View Related

C/C++ :: Applying Limit To Recursive Depth?

Jul 9, 2014

I wrote this code, but now need to apply a limit to the recursive depth. This is the format that I have to use. How would I pass a limit so that it stops after a given number? I'm just confused about where to apply it.

int compute_edit_distance(char *string1, char *string2, int i, int j, int limit) {
if (strlen(string1) == i) return strlen(string2) - j;
if (strlen(string2) == j) return strlen(string1) - i;
if (string1[i] == string2[j]) return compute_edit_distance(string1, string2, i + 1, j + 1, limit);

[Code] .....

View 4 Replies View Related

C/C++ :: How To Implement Depth-First-Search With Adjacent Matrix

Nov 1, 2014

What I have done : Created functions to accept inputs from user and read,print out adjacent matrix.

What I need : How do I start DFS in adjacent matrix so that I can output the vertices of each connected component of a graph? I'm confused with adjacent matrix and the term 'component'.

#include <stdio.h>
#include <iostream>
#define maxV 8
using namespace std;
int V,E,x,y;
int a[maxV][maxV];

[Code] .....

View 7 Replies View Related

C++ :: Convert SUDOKU Solver From Depth-First To Breadth-First

Mar 5, 2013

Code:
/* Sudoku solver using dept-first search*/

#include <iostream>
#include <stack>
using namespace std;
struct valpos//structure which carries information about the position of the cell and its value {
int val;
int row;
int col;

[Code] ....

View 3 Replies View Related

C++ :: Program That Will Display Name / Address And Age?

Jun 21, 2014

C++: write a c++ program that will display your name, address and age..

View 3 Replies View Related

C++ :: Program To Display Even Number From 100 - 200

Jan 23, 2014

i wrote this program to display even number from 100-200. But visual c gives me this error with undeling the "a" in if statement. Error1error C2106: '=' : left operand must be l-value

#include<iostream>
#include<conio.h>
using namespace std;
void main(){
for(int a=100;a<200;a++){
if(a%2=0)
cout<<a<<endl;
}
_getch();
}

View 1 Replies View Related

C++ :: Program To Display Multiplication Tables

Feb 8, 2014

I have to write a program to display multiplication tables. I have written the following code:

Code:
#include <iostream>
#include <cstdio>
using namespace std;
int main(){

[Code] ....

View 2 Replies View Related

C++ :: Program That Display Prime Numbers From 1 To 100

Oct 4, 2014

This is a program that display prime numbers from 1 to 100. it has problem linking when i run the program.

#include <iostream>
class Prime {
public:
int PrimeNo();
int Display();
};
// class Prime number
int Prime::PrimeNo()

[Code] ....

View 3 Replies View Related

C++ :: Program To Display First 40 Fibonacci Numbers

Feb 25, 2014

Write a program that displays the first 40 Fibonacci numbers. A Fibonacci number is created by add the previous two, with the first two always being 0 and 1. A partial sequence is as follows:

0, 1, 1, 2, 3, 5, 8, 13, 21,….

Your table must display 6 numbers per row and use a spacing of 10 for each number. Don’t forget to include the header file “iomanip” at the top and use “setw()”. You will need to turn in an algorithm, source code and output.

Here is what i have but i get errors!

#include <iostream>
using namespace std; {
int FirstNumber = 0;
int SecondNumber = 1;
int NumberOfNumbers = 2;
int NewNumber;

[Code] .....

View 3 Replies View Related

C++ :: Program To Display AM/PM With Current Time?

Feb 14, 2013

I'm trying to display the AM/PM on my program:

Also is there a way to display the time only instead of the date? How will i change the program to display the time in standard 12 hours, instead of 24 hours?

#include <iostream>
#include <time.h>
using namespace std;
int main()
{
time_t tim;
time(&tim);
cout << ctime(&tim);
}

View 1 Replies View Related

C++ :: Program To Display Percentage Of Calories Come From Fat

Mar 18, 2013

Write a program that asks the user to enter the number of calories and fat grams in a food item. The program should display the percentage of the calories that come from fat. One gram of fat has 9 calories, so:

(Calories from fat) = (fat grams) * 9

The percentage of calories from fat can be calculated as:

(Calories from fat) / (total calories)

Extend as follow

1. The user first enters from a menu whether it is breakfast (B or b), lunch (L or l) or dinner (D or d). Use character and process by a switch.
2. The threshold for low calorie is different, for breakfast 10%, lunch 20%, dinner 30% (this value has to be assigned to some threshold variable in the above switch).
3. Include validation of menu choice.
4. In case any validation fails, display detailed error and exit the program by calling return 1 or return EXIT_FAILURE
5. Display the % from fat with one decimal digit.

Example 1:
What you have to eat:
B - breakfast
L - lunch
D - dinner
What you have: C
Error: C is not a valid menu choice

Example 2:
What you have to eat:
B - breakfast
L - lunch
D - dinner
What you have: L
How many calories: 600
How many grams of fat: 10
Your food has 15.0% calories from fat
It is a low calories food

Process the menu in a switch, setting the threshold as either 10, 20, or 30%. The rest of the program will be the same regardless what was the menu choice.

Incremental development: first do the textbook problem without input validation, then extend with validation, then extend for the additional parts.

View 4 Replies View Related

C/C++ :: Program That Will Display Morse Code

Apr 28, 2015

IM trying to make a simple program that will display morse code. Ex if you type 0 print should be (-----) and all the way up to 5. The problem is though that all printf displays all the numbers and not executing only the assigned variable.

#include<stdio.h>
int main(void) {
int a , b , c , d , e, f, x;

a = 0;
b = 1;
c = 2;
d = 3;
e = 4;
f = 5;
x = 6;

[Code] ....

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved