C++ :: Printing Even And Odd Numbers In Alternating Pattern?

Nov 23, 2014

We never really had a thorough discussion yet about if-else statements and while.. but our teacher already gave us a difficult assignment..

We should write a program the accepts a number , n, and displays the first n values of the number series:

the pattern to be print was like this 1 1 2 3 4 5 8 7 16 9 32 11 64 13...

alternating odd and even numbers using while and if-else statements

if you input n, the output will print only until 1 1 2 3 4 5 8 7

View 2 Replies


ADVERTISEMENT

C/C++ :: Printing Square Pattern Of Asterisks Based On User Input

Dec 15, 2014

I have to make a program that displays a square of asterisks based on the users input. Here is what I have so far.

#include<iostream>
using namespace std;
int main(){
int number;
cout << "Enter a number: ";
cin >> number;
for (int i = 0; i < number; i++){

[Code] ....

But the square needs to be hollow like this. So if the user enters 5 then the following square will be shown.

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

How to make it do this.

View 11 Replies View Related

C/C++ :: Pattern Recognition For Numbers?

Jan 3, 2015

i have a .txt file with a bunch of numbers(1...99), millions of them, and i would like to make a program that recognizes patterns(if exists, i don't know) of numbers in this file. What will be the starting point? How could i do that? I read i could do that with Neural Network. Is there other way?

View 11 Replies View Related

C++ :: Reverse Alternating Words In A String

Nov 24, 2014

I'm trying to create a small program to reverse every alternate words in a string.

OUTPUT: The esoum was thgauc in a peg.

#include<iostream>
#include<string>
using namespace std;
int main() {
string sentence, reversed_sentence, buffer;

[code].....

View 6 Replies View Related

C++ :: Receive Integer X And Print Alternating Alphabetic Characters

Feb 6, 2015

Q1. Recursive function that receives an integer x and prints the alternating alphabetic characters.

Write a main function to test the function;

ENTER NUMBER : 4

A C E G

Q2. Define a void function that finds the smallest value in the array and number of its occurrences. Also, it finds the largest value in the array and number of its occurrences.

ENTER 4 NUMBERS:
1 12 5 41 41

THE BIGGEST IS 41 AND IT OCCURS 2 TIME
THE SMALLEST IS 1 AND IT OCCURS 1 TIME

View 17 Replies View Related

C++ :: Printing 10 Numbers Per Line?

Nov 3, 2013

I'm working on a program that prints every even number from 100 to 200. How i would be able to print 10 numbers per line?

Code:
#include <iostream>
using namespace std;
int main()
{
int x;
for (x=100; x<=200; x++)
cout <<x++<< endl;
system("pause");
return 0;
}

View 2 Replies View Related

C++ :: Printing Unspecified Set Of Numbers?

May 8, 2014

how are we able to print out a random number (after using srand() and rand() ) - where you there is an unspecified amount of variables given. So, if the user selects yes to have another number given, how are we able to show the previous numbers and the current one?

View 1 Replies View Related

C :: Printing 21 Different Numbers That Are Randomly Generated?

Mar 2, 2014

The program is supposed to be printing 21 different numbers that are randomly generated. Why am I getting the same number 21 times? Using dev C++ compiler.

Code:

/*prints random numbers between 1 - 99*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

[Code]......

View 3 Replies View Related

C++ :: Printing Square Free Numbers?

Feb 27, 2014

I'm currently trying to write a program that takes an integer input from the user and displays that number of square-free numbers. I've gotten most of the program to work, but I encounter an error during the noSquare function that causes it to print incorrectly.

A square-free number is a number that is not evenly divisible by the square of any prime number. It's hard to see the bold in the code area, but it begins after the "//I think below is where the problem is"

#include <iostream>
#include <vector>
using namespace std;

[Code]........

View 1 Replies View Related

C/C++ :: Printing Square Free Numbers

Feb 27, 2014

I'm currently trying to write a program that takes an integer input from the user and displays that number of square-free numbers. I've gotten most of the program to work, but I encounter an error during the noSquare function that causes it to print incorrectly. I have bolded the area where I believe the problem is what I am doing wrong.

The problem with the program is that it prints ALL numbers from 1 to the input number instead of just the square-free.

A square-free number is a number that is not evenly divisible by the square of any prime number ....

#include <iostream>
#include <vector>
using namespace std;
bool noSquare (int num); //Function to determine if the number is square-free
vector<int> getPrimes(int num); //Function to get a vector of all primes below num
bool isPrime (int number); //Function to determine if individual numbers are prime
int main()

[Code]...

By the way, the in the middle of the code was me trying to bold a section, not an actual part of the code. I can't seem to find where to edit my original post.

View 3 Replies View Related

C++ :: Printing The First N Prime Numbers (user Input)

Jan 15, 2014

//Finding prime numbers
#include <iostream>
using namespace std;

[Code]....

/*The program currently prints all the prime numbers up to n (For example, if 7 is entered, it prints out: 1, 2, 3, 5, 7. What I want it to do, is print out the first 7 numbers; 1, 2, 3, 5, 7, 11, 13.

View 1 Replies View Related

Visual C++ :: Printing 2 Arrays With 10 Numbers Per Line

Jan 14, 2014

i got 2 arrays, how would i print 10 numbers per line, so that would be 5 numbers from each array.

array1[40];
array2[40];

array1 array2// array1 array2// array1 array2 // array1 array2 // array1 array2
array1 array2// array1 array2// array1 array2 // array1 array2 // array1 array2
array1 array2// array1 array2// array1 array2 // array1 array2 // array1 array2

...... and so on

how can i put this in a loop?

and so on but there are 80 elements so i cant go one by one.

View 5 Replies View Related

C/C++ :: Can't Get The Right Square Pattern

Jul 4, 2014

I've been working on this code that should be looking like

1 3 5 3 1
3 5 7 5 3
5 7 9 7 5
3 5 7 5 3
1 3 5 3 1

but mine appears like this

1 3 5 3 1
3 5 7 5 3
5 7 9 7 5
3 3 5 7 9
1 3 1 3 5

This is the code I've got for now, I just don't know which logic I need to fix

int main(){
int r;
cout << "Rows?" << endl;
cin >> r;
for (int i = 1; i <= r; i+=2){
for (int j = i; j <= r+i; j+=2){
cout << j<< " ";
} for (int k = i+2; k >= i-1; k-=2){

[code]....

View 2 Replies View Related

C++ :: Display A Pattern Using Loops

Oct 17, 2014

I have spent at least an hour trying to display this pattern and I am not getting anywhere.

Pattern C
1
21
321
4321
54321
654321

This is as far as I got
#include <iostream>
#include <iomanip>

[Code]....

View 4 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 :: Textual Analysis - Pattern Matching

Feb 11, 2014

I am looking to write a program that, given a particular word, looks at a plain text document and gives a list of words that appear within x words of the given word along with a count of how many times it appears.

Do I need to use regex to do the pattern matching here? Is there a particular data structure that I should use that is particularly suited to a task like this? I don't want to reinvent the wheel, it seems like there should be libraries that would already do this sort of thing but searches have turned up nothing.

View 5 Replies View Related

C++ :: Creating Diagonal Pattern By Given Function

Nov 5, 2013

How to create a diagonal pattern by the given function

void diagonal(int size, char op)

The function takes in 2 arguments, size and op and displays a diagonal line of op char. for example, diagonal (5,#) will produce the following output.

#
#
#
#
#

View 4 Replies View Related

C++ :: Selecting Design Pattern For Validation

Jan 21, 2015

I am looking into some design pattern which works for validation.

I thought about using strategy but not sure whether its correct or not

View 3 Replies View Related

C++ :: Design Pattern For Function Operation

Dec 11, 2014

Any design pattern allows to describe operation like the following.

MyFunctionObject f;
//Init f...
MyFunctionObject g;
//Init g...
MyFunctionObject h = f(g) + g;

[Code] .....

I'm interested in design pattern which permits to model this kind of structure, if there's of course...

View 7 Replies View Related

C++ :: Way / Pattern To Avoid Copying Data

Apr 19, 2013

I have a class buffer, which holds a std::string as member, and a socket_receive function:

struct buffer {
string data;
buffer() {}
buffer(buffer& b) : data(b.data) {}
};
buffer socket_receive() {
buffer tmp;
tmp.data = "1234";
return tmp;
}

so when I write

buffer b = socket_receive();

there is a copy constructor, and the tmp variable is constructed and destructed, is there anyway to improve the performance?

I tried the new c++11 move(), but seems even worse, I must be doing wrong with move(), but I don't know how.

#include <iostream>
#include <string>
#include <ctime>
using namespace std;
struct buffer {
string data;

[Code] .....

View 4 Replies View Related

C/C++ :: Stopping Case For Asterisk Pattern?

Dec 1, 2014

So, I'm going to write a recursive function for a asterisk pattern but I'm stuck figuring out how to create a stopping case for it, better yet, I'm unable to describe the pattern completely.

*
**
-*
****
--*
--**
---*
********
-----*
-----**
------*
-----****
-------*
-------**
--------*

( - represent white spaces )

What I've been thinking:

* Every odd row has 1 * with 1 incremented white space

* Every "pair" of asterisks equals 8 total (EX. 8 one pair *'s, 4 two pair *'s, 2 four pair *'s)

Unfortunately, that's all I got. how I can represent this as I function. Once I figure out what my stopping case should be, I think I can do the coding on my own.

View 1 Replies View Related

C# :: Unit Of Work And Repository Pattern

Oct 18, 2014

I have implemented the IRepository and UnitOfWork Patterns in my project and I have made a little tweak in the UnitOfWork pattern .

public class UnitOfWork : IDisposable {
private DataContext m_Context = new DataContext();
private bool m_disposed = false;

#region Repositories
private GenericRepository<Product> m_ProductRepository = null;
private List<object> m_RepositoryList = new List<object>();
#endregion

[Code] ....

In my UOW class I have the public property ProductRepository. Now my idea was instead of creating a public property for every repository that I have, I created the generic method GetRepository<T> to dynamically create repositories.

Do you think that this change will have bad side effects. I think that it will improve the maintainability of the code.

View 1 Replies View Related

C/C++ :: Can Use Strtok For Splitting A String With A Certain Pattern

Oct 31, 2012

I have a string like "THIS::IS::THE:EXAMPLE::STRING"

I want to split the string to tokens based on "::".

The tokens should be:

THIS
IS
THE:EXAMPLE
EXAMPLE
STRING

View 1 Replies View Related

C++ :: Nested Looping To Create A Pattern

Jul 15, 2012

I am working on some coursework for university at the moment, and one of the questions asks me to 'write a function that will generate the following pattern using nested looping techniques.'

Pattern:

- . . . . . . .
. - . . . . . .
. . - . . . . .
. . . - . . . .
. . . . - . . .
. . . . . - . .
. . . . . . - .
. . . . . . . -

So far I have the following code, but when I compile it I get a host of different errors.

#include <iostream>
int main() {
int A[8][8],i,j;
for(i=0;i<8;i++) {
for(j=0;j<8;j++) {

[Code] ....

How to add code tags on this?

View 13 Replies View Related

C++ :: Singleton Pattern - Delete Pointer Twice

Feb 22, 2012

environment : qt creator 4.7

code:

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
class singleTon {

[Code] ....

this is a singleton pattern first,it doesn't matter, why I could delete this pointer twice?because the gcc compiler?That mean in the surface, "delete pInstance1;" this movement just mark the memory pInstance1 has been deleted but not real?does any one encounter this phenomenon?

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







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