C++ :: Display All Composite Numbers From 0 To 1000?

Feb 21, 2013

Create a program that will display all the composite numbers from 0 to 1000 and has a maximum column of 5 . A composite number is a positive integer that has at least one positive divisor other than one or itself. In other words a composite number is any positive integer greater than one that is not a prime number.

SAMPLE OUTPUT:

4 6 8 9 10
12 14 15 16 18
20 21 22 24 25
26 27 28 30 32
....and so on.

View 6 Replies


ADVERTISEMENT

C :: Display Histogram Of 1000 Gaussian Distributed Numbers

Mar 5, 2013

I'm writing a program to display a histogram of 1000 Gaussian distributed numbers. I've generated the numbers using rand and now need to transform them. I have found the following formula to use

f(x) = exp(-x^2 / (2*sigma^2)) / sqrt(2*pi*sigma)

And I am unsure how to implement this into a function.

View 3 Replies View Related

C++ :: Show All Composite Numbers 1 To 100 - 5 Columns?

Feb 25, 2013

This code is show all the composite numbers1 to 100. how can i add a limit of 5 column in this sample program??

#include<iostream>
#include<iomanip>
#include<conio.h>
using namespace std;
int main(){
int i,j;

[Code] ....

View 1 Replies View Related

C++ :: Find All Prime Numbers From 1 To 1000?

Jan 9, 2013

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

[Code].....

View 10 Replies View Related

C/C++ :: Sum Up All Numbers Between Start And End And Compare This Sum To 1000

Oct 7, 2014

Sum up all the numbers between start and end. Lastly compare this sum to 1000.

--so i got the first part, but how to compare the sum to 1000.

View 3 Replies View Related

C/C++ :: Selectively Choose Only Numbers Greater Than 1000 In Array?

Aug 4, 2013

I am doing my assignment that will calculate total tax amount per day and per week and finally sum those up.

One of the requirement is to filter out any number in the array that is less than 1000 to be assigned a value of zero instead of the stored value so as not to add it in the calculation. How to fulfill this requirement.

View 2 Replies View Related

C++ :: Display Last 1000 Lines From Multiple Text Files (log Files)

Jan 16, 2014

I am writing a piece of code that requires me to display the last 1000 lines from a multiple text files (log files). FYI, I am running on Linux and using g++.

I have a log file from which - if it contains more than 1000 lines, I need to display the last 1000 lines. However, the log file could get rotated. So, in case where the current log file contains less than 1000 lines, I have to go to older log file and display the remaining. For e.g., if log got rotated and new log file contains 20 lines, I have to display the 980 lines from old log file + 20 from current log files.

What is the best way to do this? Even an outline algorithm will work.

View 6 Replies View Related

C++ :: Creating (Composite) Vector Array Field?

Jan 3, 2013

In a numerically intensive code, I have a Cartesian vector class Vector3d which has the normal operator overloading and basic functions such as dot product, magnitude, etc. For simplicity, assume that it is not a templated class and its components are of type double.

I frequently need large 1-d arrays (e.g. stl vectors) of Vector3d. Two use-cases must be satisfied:

1) The trivial case in which the data are stored as stl vectors of Vector3d;

2) The more difficult case where the individual components are stored as stl vectors of double, and are not guaranteed to be contiguous in memory (so one cannot rely on "stride").

Assuming the array lengths are all identical, I'd like to be able to access both types in a single loop. The straightforward way for case 2) is to construct a temporary Vector3d from the three components (indexed with the loop index). However, I would prefer not to incur the overhead of the constructor.

Is it possible using template metaprogramming. Ideally I'd like a CompositeVector3d that inherits from Vector3d and is constructed with the component vectors, but can be dereferenced using the loop index in the same way as one would do with case 1.

I am not looking for the typical template metaprogramming utility of being able to operate on the entire array without explicit loops. I just want the syntactic "sugar" whereby CompositeVector3d and Vector3d act the same, plus the avoidance of the cost of the constructor. I am not averse to using an additional templated class (perhaps a Field or a View class) to access the basic storage in both case.

Is it possible to do this without using a full template metaprogramming utility?

View 1 Replies View Related

C/C++ :: User Input - Number Prime Or Composite?

Mar 8, 2014

User will input a number in the range of 2 and 2^63-1 and the program will decide whether it's prime or not by a simple 'YES' or 'NO'.

I figured out a code:

#include <stdio.h>
#include <string.h>
main() {
unsigned long long n,i=3; int temp=0;
int t;
scanf("%d",&t); //Number of test cases

[Code] ....

Now this code works for normal inputs but whenever I try it with large primes in tat range, like 987654321987654329 or 9223372036854775783 it does not work />.

I tried to print the values of i to check the limit to which it runs.. and I found it 23697, whose square is 561547809 - nowhere near about the input primes.

View 10 Replies View Related

C++ :: Display Only Numbers At The Last?

Aug 16, 2012

i want to to apply a validation for an field which is Vehicle number in that the last four should be digits for ex:

AP1234 something like this it and it shldnt have 0000 at the last ...

View 5 Replies View Related

C++ ::  How To Display Numbers With Decimals

Aug 28, 2014

float put;
put = 6/120;
cout << put;

This outputs 0. Why is it so and how can I make it output 6/120 in a more precise way?

View 1 Replies View Related

C++ :: Display A Table Of Numbers From 50 To 150

Apr 2, 2013

Using for loop .....

View 15 Replies View Related

C/C++ :: 100 To 1000 Divisible By 5 And 6

Oct 2, 2014

Write a program that displays all the numbers from 100 to 1,000, ten per line, that are divisible by 5 and 6. Numbers are separated by exactly one space.

#include <iostream>
#include <stdlib.h>
using namespace std;

[Code]....

View 8 Replies View Related

C++ :: Display Remainder Of The Square Of Numbers From 100 To 10

Mar 31, 2013

Display the remainder of the square of numbers from 100 to 10. This square of numbers must be divisible by the numbers from 100 to 10 respectively. what i need to in this

View 3 Replies View Related

C++ :: How To Display File With Numbers On The Screen

Apr 1, 2013

I have a file with numbers and want to display it on the screen.

View 15 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++ :: Comparing Three Numbers And Display Largest

Oct 9, 2013

My display is producing:

Enter the first number:234
Enter the second number:2
Enter the Third number:3
The largest number is 3

#include <iostream>
using namespace std;
double larger(double n1, double n2, double n3);
int main() {

[Code] ....

View 1 Replies View Related

C++ :: Display Prime Numbers Using Loop

Feb 3, 2013

We were asked to make a program which displays the prime numbers within the range you inputted... like for example i entered 20 as the upper limit and 1 as the lower, then the program must display all prime numbers within 20 and 1..

and so my problem is, i get to display the prime numbers, but 2, 3, 5, and 7 can't because it think it's with the if statement i made within the loop? (Code below)

#include<iostream.h>
#include<conio.h>
void prime (int up, int low);
main() {
clrscr();
int Upper, Lower, i;

[Code] .....

View 6 Replies View Related

C++ :: Display Numbers In Binary Search Tree - Getting 0s

Jan 31, 2015

I want to display the numbers in a bst but all I get are 0s, what is wrong with my code that is causing this?

#include <iostream>
using namespace std;
class binarySearchTree {
private:
class TreeNode {
friend class binarySearchTree;
int value;

[Code] ....

View 1 Replies View Related

C++ :: Display Arithmetic Sequence After Adding All Numbers

Oct 7, 2013

This code is suppose to display arithmetic sequence after it has to add all the numbers together without a formula.

for example: the starting number is 5, common difference is 3, the term is 9

the sequence would display as: 5, 8, 11, 14, 17, 20, 23, 26, 29

the sum is: 153

with my code I've managed to get 8,11

To get the sum, I am restricted to using a "for" loop. For sequence, I am using a while. I am trouble developing the while loop to display the sequence and getting the sum for the for loop.

#include <iostream>
#include <cmath>
#include <stdlib.h>
using namespace std;
int main() {
double a, d, n,i,sum,j;

[Code] ....

View 3 Replies View Related

C++ :: Using Array - Display Highest And Lowest Numbers

Oct 1, 2013

I have everything down except for the highest # and lowest number being displayed.

The arrays are 23, 4, 76, 89, 12, 43, 37, 67, 21, 14.

I have the average which is 38.6 but i stuck getting highest number and lowest.

View 7 Replies View Related

C :: Display Numbers That Are Passed As Literal ASCII Characters To LCD

Mar 20, 2014

What shall I learn in order to send values from 0.00 to 5.00? I'm working with they Hitachi 16x2 LCD display.I've been sending/displaying literal values on it all day.

Code:

SendCharater(unsigned char val)

where the variable val corresponds to the LCD character table.I can also send Hello World to the display, like so:

Code:

void putsXLCD(unsigned char *buffer){
while(*buffer) // Write data to LCD up to null
{
while( BusyXLCD() ); // Wait while LCD is busy
SendCharacter(*buffer); // Write character to LCD
buffer++; // Increment buffer
}
return;
}

I could type in putsXLCD("5.00") in order to display it on the LCD, but how do I implement this automatically for values, e.g. 0.00 to 5.00?It appears I can only pass literal values through the function SendCharacter, meaning that in order to display "0" I have to pass the value 0x30 (the hex value of "0" on the LCD Table).

My current thought process:Much like passing "Hello World" in the function putsXLCD(), I need to assign a pointer that points at each value in the "array" that I need to send. E.g., I need to send 3.24, so I need to point to "3", fetch the corresponding hex value in the LCD table, in this case 0x34, and the pass this 0x34 into the SendCharacter function, and so on. So, if this is the case, how can I fetch the corresponding hex value?

View 7 Replies View Related

C :: Read 15 Numbers And Display Each Number On Separate Line

Oct 21, 2014

Program to read in 15 numbers and display them as follows //each number on a separate line

Code:

# include <stdio.h>
# define MY_ARRAY 15
int main(){
int i ;
printf("please enter 15 numbers

[Code] ....

Error that i get from compiler:
Error E2062 array1.c 14: Invalid indirection in function main()
Error E2062 array1.c 19: Invalid indirection in function main()
both pointing to the separate "scanf"

View 6 Replies View Related

C++ :: User To Enter Decimal Value Then Display Its Corresponding Binary Numbers

Sep 13, 2013

Create a program that will ask the user to enter a decimal value (1-999999) then display its corresponding binary numbers. Repeat this process until the value entered is equal to 0. Use the following Function Prototype:

void BinCodes(int value);
Sample Input/Output:
Enter a Decimal: 35
Binary: 100011
Enter a Decimal: 184
Binary: 10111000
Enter a Decimal: 0

View 4 Replies View Related

C/C++ :: Program To Display First 10 Largest Numbers Present In A File?

Oct 15, 2012

there is a file contains only a numbers ,we dont know how many numbers present in that file.so i want a program to display top n largest number present in that fie.(n may be 5,10,12 like that.)

View 3 Replies View Related







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