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


ADVERTISEMENT

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 :: Loop Statement To Print Numbers From 1 To 10 In Reverse Order Separated By Star

Apr 21, 2013

Write a for loop statement to print the numbers from 1 to 10 in reverse order separated by star :

10*9*8*7*6*5*4*3*2*1

i try to do it but it show me like this :

10*9*8*7*6*5*4*3*2*1*

how do i write to show me like the first one ?

View 10 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

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 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++ :: Add Row To Irregular Matrix?

Apr 7, 2013

//matrix :

12 5 35 35 35 65 170
48 15 190 85 27 27 24
100 315 119 600 116 129 70
88 110 145 90 90 90 90
77 85 130 55 210 122 200  

// the row :

152 152 149 155 170  

// matrix after adding the previous row :

12 5 35 35 35 65 170
48 15 190 85 27 27 24
100 315 119 600 116 129 70
88 110 145 90 90 90 90
77 85 130 55 210 122 200
152 152 149 155 170  

We use the pointer.

- Can I print out the irregular matrix?

View 4 Replies View Related

C :: Program To Recognize Pattern Of Signals (linux Environment)

Mar 6, 2015

I need to write a c program that can receive signals and recognize a certain pattern (SIGUSR1, SIGUSR2, SIGUSR1, SIGUSR2). once the pattern is caught the program terminates itself.

I am able to send the signals to the program from a different process, but I am unsure on how to get the signal handler to recognize the pattern. here is what i have so far:

Code:
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
sig_atomic_t sigusr1_count = 0;
sig_atomic_t sigusr2_count = 0;

[Code] .....

I just need getting the program to be able to catch that specific pattern.

View 4 Replies View Related

C :: Draw Magen David Star

Apr 18, 2014

problem to draw magen david star ,i find code that draw pyramid of starts. how can i modify this code to receive magen david star ?

Code:
#include <stdio.h>
int main() {
int rows, star, spaces;
char bukva='A';
int number_of_stars = 6;
int number_of_rows = number_of_stars;

[Code]....

View 4 Replies View Related

C# :: How To Fix Space For Output Of Star Triangle

Mar 7, 2015

When i set any 3 inputs length, the space should be move in right position. I try to fix the space move forward into 1 space, but don't know why it doesn't work. Specially, when the number is 4 or 5. The space didn't move 1 space.

using System;
class length{
static void Main(){
int i,j,k;
string star = "*";
string s1 ="";
string s2;
int[] nums = new int[] {3,4,5};

[Code] .....

View 2 Replies View Related

C# :: Find Closest Star To The Earth

Apr 19, 2015

Consider a coordinate system for the Milky Way, in which the Earth is at (0; 0; 0). Model stars as points, and assume distances are in light years. The Milky Way consists of approximately 1012 stars, and their coordinates are stored in a file in comma-separated values (CSV) format one line per star and four fields per line, the first corresponding to an ID, and then three floating point numbers corresponding to the star location. How would you compute the k stars which are closest to the Earth? You have only a few megabytes of RAM.

View 1 Replies View Related

C++ ::  can't Get Program To Print Only Available Seats

May 1, 2014

I can't get my program to print only AVAILABLE SEATS; instead it prints Both Available and Taken.

//Program allows you to delete and add seats to the Airplane. Also to upload seat settings as a text file.
#include <iostream>
#include <fstream> //file stream for text file
#include <string>
using namespace std;

[code].....

View 6 Replies View Related

C++ :: A Program To Print Big Letters?

Nov 28, 2013

I need help writing a program where I use small letter to write names in Big letters. (I dont know if you understand what i mean). Follow link to description.

[URL]

View 6 Replies View Related

C++ :: Program To Print Sum Of Even And Odd Numbers

Apr 14, 2013

I am writing a program that prints the sum of even and odd numbers and here is my code

#include <iostream>
using namespace std;
const int SENTINEL = -999;

int main() {
int integers = 0;
int even = 0;
int odd = 0;

[Code] ....

Nut now in the output it adds -999 to the odd numbers ....

View 3 Replies View Related

C :: Program To Print The Length Of A String

Oct 20, 2013

Well what the title says, but I can't get it done. This is what I got

Code:
#include <stdio.h>#include <string.h>
int main(void)
{
char word;
int count;
printf("Enter a word.

[Code] ....

View 4 Replies View Related

C :: Program To Print Letters In Given Notation

Feb 11, 2014

I have to develop script in C to print the alphabets in given notation.

Please check the attachment.

View 4 Replies View Related

C++ :: Print Asterisks To Correspond To Program

Mar 16, 2014

i have to make two functions one recursion that ask the user to enter number of rows and i use recursion to tell him how many pins there are ex. user enters 5 there are 15 pins. I did this function now i need a function that prints an asterisk triangle for my recursion function so for 15 it should look like this

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

i tried many times but can't make it descend like that i can only get like a right triangle..the hard part is that it goes with the users number so if they enter 3 for example it should be 3 rows.

int pins(int n){
if(n==0){
return 0;

[code]....

View 1 Replies View Related

C++ :: Program To Print Out X / Y Click Coordinates?

Jan 16, 2013

I use the AS/400 warehouse system, and I need to be able to automate typing one letter in several different locations to speed things up.

My thoughts are:
1. Find out how to make a program that will determine x, y coordinates of mouseclicks, and then use software to use macros to change information.
2. Build a program that will complete a single process by repeating set mouse clicks and keystrokes.

We recieve HUGE transfers from a warehouse across the country, and have to change the first character of the name of bin locations - and after a few pages it gets VERY tedious.

View 4 Replies View Related

C++ :: Program Must Print Out 5 Random Numbers

Feb 10, 2014

The program must print out 5 random numbers, from 1 to 45 and 100 different sequence.. Now I want each number of sequence to be different and not the same....

for example

1,2,3,4,5
6,7,8,9,10
....
...
..

here is my code:

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main () {
int xRan1;

[Code] ....

View 2 Replies View Related

C/C++ :: Make Program To Print Out String

Nov 24, 2014

I'm trying to make a program in C where the user enters a string and it prints a word for example (name) in lowercase then the same word again but in capitals and lowercase like this (NnAaMmEe).

my code is below;

#include<stdio.h>
#include<ctype.h>
int main()

[Code].....

View 1 Replies View Related

C/C++ :: Program To Print Out Binary Value Of 16 Bit Number

Sep 22, 2013

Write a program to print out the binary value of a 16 bit number.

Create integers i, count, and mask.

Set 'i' to a hex value of 0x1b53.

Set mask to a value of 0x8000. Why?

print a line to show the hex value of i and then the leader for the binary value like this: Hex value = 1b53 Binary=

Use a for loop to loop 16 times and print 16 digits, using count as the loop counter

To test for each digit value, bitwise and 'i' with 'mask'

when the result for the bitwise and is true, print the number '1'

when the result for the bitwise and is false, print the number '0'

then shift mask one place to the right

print a new line and then quit

Use prtscrn and make a hard copy of the code with the console output.

Extra: use the modulus of count and print a space after every 4th digit to make the binary easier to read

The output should look like this: Hex value = 1b53, Binary= 0001 1011 0101 0011

so far this is what i have

#include <stdio.h>
#include <stdlib.h>  
int main() {
    int i, count, mask;
    //   1B53  0001 1011 0101 0011
    //   8000  1000 0000 0000 0000
    i = 0x1b53;

[Code] ....

it is telling me that there is an "else" without previous "if", also is the program that I wrote correct?

View 3 Replies View Related

C :: Program To Print All Of Prime Numbers To Screen

May 29, 2013

I'm trying to write a program that prints all of the prime numbers to the screen. I'm getting angry because it only prints EVERY number. I think it has something to do with the bool change not being able to leave the for-loop but how to fix it.

Code:
#import <stdio.h>
#include <stdbool.h>
int main(void){
printf("
The Primes Are: 1");

[Code] ....

View 3 Replies View Related

C :: Program Doesn't Print Data From Socket

May 7, 2014

I created a basic socket server, which listensing for incoming udp data. When I run the netcat program, I get a response:

Code:
$ nc -luv 1732
Connection from 10.50.11.12 port 1732 [udp/*] accepted
(?@??8?? ??.?n?5
(?@??8?? ??.?n?5|?>)
(?@??8?? ??.?n?5|?>)
^C |?>)

But with my c program it doesn't give the response. It should say something like "here is the message: " and then give a message.

Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>

[Code] .....

View 2 Replies View Related

C++ :: How To Make A Program That Print Out Factors Of Integer

Oct 26, 2013

I want to make a simple program that will print out the factors of an integer. My program right now only outputs "The prime factors of 221 are 221, 221, 221, 221"... Where it should be "The prime factors of 221 are 1, 13, 17, 221"

#include <cstdio>
int factorsOf(int x);
//function
int main() {
int x = 221;
printf("The factors of 221 are ");

[Code]...

View 3 Replies View Related

C++ :: Print Out Number Of Twin Primes Program

Jul 27, 2014

This program prints out the total number of up to 100,000. How to do is to print out the number of twin primes up to 100,000. Is it as simple as adding an if statement "if(primesList[j] - i == 2)"?

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main() {
int primesCount = 0;

[Code] ......

View 4 Replies View Related







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