C :: Print Triangle Pattern Using One Loop And Recursion?

Dec 18, 2013

Q.print triangle pattern using one loop and recursion

eg: 5

Code:

#include <stdio.h>#include <conio.h>
void pattern(int n,int N) {
int i,c=1;

[Code]....

View 8 Replies


ADVERTISEMENT

C++ :: Recursion - How To Print To The Screen Value Of N After It Has Been Multiplied

Mar 20, 2013

How to print to the screen the value of n after it has been multiplied.

For example: if I use cout << "n: " << n << " power: " << power << "
"; I

can see the variable "power" decrementing by 1, but I don't see the variable "n" incrementing with its new value after it has been multiplied by n * n.

#include <iostream>
using namespace std;
typedef unsigned short int USHORT;
typedef unsigned long int ULONG;

ULONG Getpower(USHORT n, USHORT power);

[Code] .....

View 2 Replies View Related

C/C++ :: Program To Print Irregular Star Pattern?

Oct 5, 2014

I am trying to write a program that will make a pattern of stars. The last line is really tripping me up. I have to make the code only using the printf("*"); printf(" "); printf("/n"); statements once. I want to accomplish this with a for loops and if statements.

It is supposed to look like this:

* - 5 spaces before *
* * - 4 spaces before *
* * * - 3 spaces before *
* * * * * * - 0 spaces before *

This is what I've tried so far:

main()
{
int i, j, k;
i=1;
j=1;

[Code]....

here are the links on codepad [URL]

I think my first approach is way off. But I think I am on to something in the second link. I'm trying to print the "*" and extra 2 times on the fourth line. In the second link the compiler appears to be ignoring the || operator. Is my syntax incorrect in the second attempt? How should I change my if statement to make this pattern work?

View 2 Replies View Related

C++ :: Program To Print Out All Booms - Minesweeper Field (recursion)

Apr 4, 2013

I'm required to write a program to print out all booms allowed requests below:

1. User will enter the address of the cell and its value.
2. Print out all booms.

How to solve it by using recursion.

View 4 Replies View Related

C++ :: Recursion To Loop Using Stack

Oct 15, 2014

I want to convert the following program into a non-recursive code using a stack and a loop:

void write(int n) {
if (n>0) {
write(n-1);
cout << n << " ";
write(n-1);
}
}

And here is the code I am using but that currently does not work, and I do not know why:

stack<int> S;
S.push(n);
while (not S.empty()) {
int k = S.top();

[Code] .....

How to simulate that recursion. I thought it was enough to push into the stack the equivalent recursive call.

View 2 Replies View Related

C++ :: Print Pattern Function That Handles Parameter As String

Sep 26, 2013

How to write a printPattern() function?

The function takes in a parameter i.e. a char pointer. It handles the parameter as a Cstyle string i.e. a NULL terminated char array. It does not make use of the stringclass or its associated functions. In other words, the function examines every char element in the array until it encounters the terminating NULL character.

Starting from this int main :

int main() {
char string1[] = "Application of C++";
printPattern(string1);
}

[Code].....

View 1 Replies View Related

C/C++ :: Recursive Function To Print Hour Glass Pattern

Oct 11, 2014

I need to make a recursive function(s) which prints the hour glass pattern. This is my code so far:

void HourGlass(int n) {
if (n==1){
cout<<"*"<<endl;
cout<<"*"<<endl;
} else {
stars(n-2);
HourGlass(n-2);

[Code] ....

Problem is, it doesn't print the spaces in front of the pattern. This is what it prints:

*****
***
*
*
***
*****

and this is what it is supposed to print:

*****
***
*
*
***
*****

Do I make a separate function for the spaces? How do I go about it?

View 7 Replies View Related

C/C++ :: Nested For Loop Pattern?

Nov 3, 2014

I'm trying to output a pattern using loops. The pattern is a plus symbol made of 3 rows of 5 x's followed by 3 rows of 15 x's and finally 3 rows of 5 x's.

I can get the program to output all 9 rows with 5 x's but I don't know how to do the 3 rows of 15 in the middle. I have tried a while loop and also an if statement but nothing seems to work.

#include "stdafx.h"
#include <iostream>
#include <iomanip>

[Code]....

View 8 Replies View Related

C :: Print The Star Equilateral Triangle

Dec 23, 2014

I use photos to express it. The answer is:

Code:
int main(int argc, char *argv[], int n) {
int i,j;
for (i=1;i<=n/2+1;i++) {

[Code]....

View 3 Replies View Related

C++ :: Print Equilateral Triangle With Asterisks?

Feb 22, 2013

how can i print an equilateral triangle with asterisks .

View 3 Replies View Related

C++ :: Void Triangle - Print Class Function

Sep 1, 2013

//Point.cpp
#include "Point.h"
#include <iostream>
#include <cmath>
using namespace std;

Point::Point() { //Initialise the point to the origin.

[Code] ....

void Triangle::print() { //print out the Triangle with the format "( (x1, y1), (x2, y2), (x3, y3) )"

How do I accomplish this? When i test with cout << _point1.print(), there's an error:

[Error] no match for 'operator<<' in 'std::cout << ((Triangle*)this)->Triangle::_point1.Point::print()'

View 4 Replies View Related

C/C++ :: Print Pascal Triangle Based On Integer N Inputted

Nov 7, 2014

void Pascal(int n){
int i,j;
int a[100], b[100];
a[0]= 1;

[Code] ....

I've been trying to make a function that prints a pascal triangle based on an integer n inputted.

View 3 Replies View Related

C++ :: Triangle In Nested While Loop Using Counters

Mar 13, 2013

How to make triangles using c++, in nested while loops.

The triangles were:
*
**
***
****
*****
******
*******
********
*********
**********

I have made a code for this:

int counter=1;
while (counter<=10){
int counter2=1;
while (counter2<counter){

[Code] .....

I was not quite sure about this one.

View 5 Replies View Related

C++ :: While Loop - Use Non-recursive Function To Make Triangle Number Sum Of All Whole Numbers From 1 To N

Jul 31, 2014

My while loop is the problem. I want to use a non-recursive function to make the triangle number the sum of all whole numbers from 1 to N.

#include "stdafx.h"
#include <iostream>
using namespace std;
int triangle(int t);

[Code] ....

View 2 Replies View Related

C :: Print Pascal Triangle And Stores It In A Pointer To A Pointer

Nov 27, 2013

I have to write a program to print pascals triangle and stores it in a pointer to a pointer , which I am not entirely sure how to do. I also have to write the file and read it, then create a binary file. Assignment is attached. I am not the best with programming and especially with pointers. I will post my code below.

Code:
#include <stdio.h>
#include <stdlib.h>
void writePascalTriangle(char *fileName, int heightOfTriangle, int **triangle) {
FILE *fp;
fp=fopen("writePascalTriangle.txt", "w");

[Code] ....

View 4 Replies View Related

C :: Can't Get Strings To Print When Using For Loop

Mar 6, 2015

I am making a program that takes the user's family names, their ages, and where they live. At the end I will be eventually averaging out their age and also printing the names of anyone who lives in Kansas.

I can't seem to get the Kansas part to work properly though.. When I execute the code, everything else works perfectly, but the Kansas part doesn't even print. Is there something different I need to do when strings are involved rather than integers/floats?

Code:

#include <stdio.h>
int main ()
{
/* variable definition: */

[Code].....

View 6 Replies View Related

C/C++ :: Cannot Get Strings To Print When Using For Loop

Mar 24, 2015

I am making a program that takes the user's family names, their ages, and where they live. At the end I will be eventually averaging out their age and also printing the names of anyone who lives in Kansas.

I can't seem to get the Kansas part to work properly though.. When I execute the code, everything else works perfectly, but the Kansas part doesn't even print. Is there something different I need to do when strings are involved rather than integers/floats?

#include <stdio.h>
int main () {
/* variable definition: */

[Code].....

View 3 Replies View Related

C/C++ :: Why Does Printf Not Print After A While Or For Loop

Jul 1, 2012

I would like the following code to print: "Why doesn't this print?" and "I would like to print the sum of nc: 5". What am I doing wrong.

#include <stdio.h>  
//Use to test ideas and formats//  
main() {
    int c, nc;      
    nc = 0;  

[code]....

My result as compiled by gcc -o testing testing.c

This prints.

test
t1,e2,s3,t4,
5,

I have not figured out how to sum and print as the above code indicates, which complicates my ability to do many of the exercises in "The C Programming Language". I am using a MacBook gcc compiler and X code as well. I cannot get the last two printf functions to work. I did the temperature example with "while (fahr <= upper)" and the printf printed.

View 7 Replies View Related

C/C++ :: Print Series Of Text From Loop

Sep 29, 2014

I'm attempting to print a series of text from this loop, but for some reason all I am getting is the sum total and the number 1, like this

1 5175.11

When I want to get it for each iteration of the loop. I've cycled over this and compared it to my other loops I've used and I'm lost as to why this isn't working. I also tried using a do while but that didn't work as well.

for (double total1 = 0; total1 < goal; total1 + save_amt) {
total2 = ((factor - one) * save_amt);
total3 = (total2 / fr_interest);
total1 = total1 + total3;
months_dis = (months_dis + one);
cout << months_dis << " " << total1 << endl;
}

View 14 Replies View Related

C/C++ :: Print 10101 And 01010 Series Using For Loop

Apr 11, 2014

10101
01010
10101
01010

I want print above series using for loop.

View 2 Replies View Related

C++ :: Print ASCII Characters - Limit In For Loop

May 1, 2015

#include<iostream>
#include<conio.h>
using namespace std;
int main(void){
clrscr();

[Code] ....

I am trying to print ascii characters but problem is If i put a limit in for loop to 255 or more than 126 the output don't stop it keeps on going

I know there is another way to this program but what i want to know this why this happen in this logic....it doesn't happen if a<=125 or less then 125.

View 7 Replies View Related

C++ :: Count Controlled Loop Than Can Print Char

Sep 27, 2012

Write a count controlled loop than can print "i" char. The user is supposed to input a integer and that integer is how many asterisks there is on the blade, in this case it is 5.

* *
** ** **---------------
*******
** ** **
* ** * -10 Rows high
** -blade always connects on second row of handle
**
**
**
**------------------

These are the steps he told us to do it in.

1) *
**
***
****
*****

2) *
**
***
****
*****
****
***
**
*

3) * *
** **
*** ***
**** ****
**********

4) * *
** **
*** ***
**** ****
**********
**** ****
*** ***
** **
* *

5)* *
** ** **
*******
** ** **
* ** *
**
**
**
**
**

View 4 Replies View Related

C++ ::  Vertical Histogram - Variables In For Loop To Print Stars

Dec 6, 2013

I want to create a vertical histogram in my code. I already made it go vertical but not the way I want it.

Example:
I want it like this:

Range1 Range2 Range3 Range4

And asterisks under each one, depending on the user input. (My code is below and doing it on here doesn't make it come out correctly)

But what I've managed to do is this:

Range1
*
*
*

Range2
*
*

Range3
*
*
*
*

Range4
*
*

Which I don't want. I want everything else to stay pretty much the same since I can only use some features such as Arrays and really basic functions.

Here is my code: (Worked fine last time I used it and I am doing it on Visual Studio 2010 (at uni) and 2013 (on my laptop)).

#include <iostream> //Start of code
using namespace std;
int MarkValueInput; //Mark entered by user
//Counter variables for ranges in While Loop
int counterlow; //Counter for low range
int countermidlow; //Counter for mid-low range
int countermidhigh; //Counter for mid-high range
int counterhigh; //Counter for high range

[Code] .....

View 4 Replies View Related

C/C++ :: For Loop To Print Given Character Number Of Times Specified By Integer

Feb 11, 2014

The function uses a "for" loop to print the given character the number of times specified by the integer.

How can I make a for loop to do that?

So.. my code looks like this:

// cpp : Defines the entry point for the console application
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void printMyInteger(int myInteger, char myChar) {

[Code] ....

So.. here is my error:

Error1error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
Error2error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
3IntelliSense: expected an expressiond:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp107Week 6

View 3 Replies View Related

C# :: Infinite Loop Random Boolean Print Statement

Feb 19, 2014

I am working on a small simple program my program fills up a air plane with customers there is 2 levels 1 and 2 and it will put that person in the spot depending on being picked.

So far i made a boolean airplane with 10 spots I can enter 1 person into the airplane with no problem but then after he sits down i get a infinite loop? I assume i maybe have to use the continue statement I feel like there is something simple that im missing i want to add more people. here is what i have

class Program
{
static void Main(string[] args)
{ bool[] planeSeats = {false, false, false, false, false, false, false, false, false, false };

[Code]......

View 1 Replies View Related

C++ :: Print Each Percent Of Loop Breaks Down For Large Loops?

Feb 22, 2012

I'm trying to make a percentage counter inside a loop, printing each completed percent of the loop as it goes. I've managed to write such code, but when I run it the percentage output breaks down (becomes negative!) for large loops. I have an example below.

Code:
#include <iostream>
#include <sstream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
using namespace std ;
int main() {

[code].....

Compiling and running the above yields the output:

Code:

...1% ...2% ...3% ...4% ...5% ...6% ...7% ...8% ...9% ...10% ...11% ...12% ...13% ...14% ...15% ...16% ...17% ...18% ...19% ...20% ...21% ...-21% ...-20% ...-19% ...-18% ...-17% ...-16% ...-15% ...-14% ...-13% ...-12% ...-11% ...-10% ...-9% ...-8% ...-7% ...-6% ...-5% ...-4% ...-3% ...-2% ...-1% ...0% ...1% ...2% ...3% ...4% ...5% ...6% ...7% ...8% ...9% ...10% ...11% ...12% ...13% ...14% ...15% ...16% ...17% ...18% ...19% ...20% ...21% ...-21% ...-20% ...-19% ...-18% ...-17% ...-16% ...-15% ...-14% ...-13% ...-12% ...-11% ...-10% ...-9% ...-8% ...-7% ...-6% ...-5% ...-4% ...-3% ...-2% ...-1% ...0% ...1% ...2% ...3% ...4% ...5% ...6% ...7% ...8% ...9% ...10% ...11% ...12% ...13% ...14%...100%

If I change the value of N to 1e7 instead of 1e8, the output is correct however!

Code:
...1% ...2% ...3% ...4% ...5% ...6% ...7% ...8% ...9% ...10% ...11% ...12% ...13% ...14% ...15% ...16% ...17% ...18% ...19% ...20% ...21% ...22% ...23% ...24% ...25% ...26% ...27% ...28% ...29% ...30% ...31% ...32% ...33% ...34% ...35% ...36% ...37% ...38% ...39% ...40% ...41% ...42% ...43% ...44% ...45% ...46% ...47% ...48% ...49% ...50% ...51% ...52% ...53% ...54% ...55% ...56% ...57% ...58% ...59% ...60% ...61% ...62% ...63% ...64% ...65% ...66% ...67% ...68% ...69% ...70% ...71% ...72% ...73% ...74% ...75% ...76% ...77% ...78% ...79% ...80% ...81% ...82% ...83% ...84% ...85% ...86% ...87% ...88% ...89% ...90% ...91% ...92% ...93% ...94% ...95% ...96% ...97% ...98% ...99%...100%

View 5 Replies View Related







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