C/C++ :: Program To Print Product Of Even Numbers And Sum Of Odd Numbers Between 1 And 30
May 20, 2014
I want to make a program to print the product of even numbers between 1 and 30 and sum of odd numbers between 1 and 30. But the answer of product is negative. The photo shows the output of the code.
#include <stdio.h>
#include <conio.h>
void main ()
{
int i, even_product=1, odd_sum=0;
for(i=1;i<=30;i++) // For loop starts here!
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;
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");
The problem is with the first "Type and Run," where the code looks like this:
Code: /* print_it.c--This program prints a listing with line numbers! */ #include <stdlib.h> #include <stdio.h>
void do_heading(char *filename); int line = 0, page = 0;
[Code] ....
I am using the gcc compiler in Ubuntu 12.04 LTS and I get the following error:
Code: print_it.c: In function "main": print_it.c:36:15: error: "stdprn" undeclared (first use in this function) print_it.c:36:15: note: each undeclared identifier is reported only once for each function it appears in print_it.c: In function "do_heading": print_it.c:49:16: error: "stdprn" undeclared (first use in this function)
I was told that "stdprn" can be recognised by a DOS based compiler and the book says I can try using "stdout" instead. It looks like this now:
Code: /* print_it.c--This program prints a listing with line numbers! */ #include <stdlib.h> #include <stdio.h>
void do_heading(char *filename); int line = 0, page = 0;
[Code] .....
It compiled OK with the gcc compiler but I only get this when I run the program:
Code: Proper Usage is: print_it filename.ext
I am not sure whether I should continue looking into this but even when I tried compiling and running it on Windows, the .exe file won't even launch. The other ones do but this first one doesn't.
Questions:
1. What should be done to make this program run? 2. Even though the book says "don't care" if the reader does not understand the items (It's Day 1/Lesson 1), I would still like it to run as I don't want to experience compiling and running problems in the future. Should I even bother doing this section of the book or is it obsolete and should be skipped?
I am making a program where the user enters numbers into an array and then a number,x. The array is sorted, then x is inserted into the appropriate place. I wrote my selection sort
Code:
void Sort(int ary[], int size) { int temp; int smallest; int current; int move; }
[code]....
put it wont print the numbers sorted when I use my print function, just the unsorted numbers.
So i have made an array and made a scanf in a for loop so it can store all numbers entered from keyboard in the array but i dont know how to put the numbers that are less than 5 in another array and then print that array out and the lenght of the array.
I did write a print function which the user put a number and then it will print out till that number
the output is correct ,, but is code correct ? or it could be better somehow ?
write a function named print_out that print all the whole numbers from 1 to n. test the function by placing it in a program that passes a number n to print_out , where this number is entered from the keyboard . the print_out function should have type void; it does not return a value. the function can be called with a simple statement:
print_out(n);
PHP Code:
# include <iostream> using namespace std; void print_out (int x); int main () { int n; cout << " enter a number : ";
I have a program in c++ to print all the binary numbers that have 64 bits. But the problem is it works only for 30 bits. Beyond that the program does not work possibly because of insufficient space availability.
my code is as below:
// C++ program to generate n-bit binary numbers #include <iostream> #include <string> #include <vector> #include <fstream> using namespace std;
// This function generates all n bit Gray codes and prints the generated codes void generateSequence(int n)
i am trying to write a program to get a number from user and then print even numbers as well as 0,2,4 and so on.what changes i should do ?
PHP Code:
# include <iostream> using namespace std; int main () { int n,i; cout << " Enter number "; cin >>n; i = 0; while ( i%2 == n) { cout <<i<<" "; i = i+1; } system ("PAUSE"); return 0; }
I am trying to print the prime numbers, so i put the numbers into the vector and then erase the non prime numbers. if i comment the break statement i get runtime error saying out of bound, but if i don't comment it out it prints the primes but it also prints the multiples of 3.
void Eratos( int length, vector< int > &v ) { int i; for (i=0; i<length; ++i) { v.push_back(i); cout <<v[i];
I am currently working on a student records program and I want it to print a '-' after every 3 digits from the Id number that I read from the file(ID number from file doesn't have the dashes). How would I do that to print it with dashes?
fin >> Temp.FirstName; fin >> Temp.LastName; fin >> Temp.Id; fin >> Temp.Quiz; for (int i = 0 ; i < 6 ; i++) fin >> Temp.Test[i];
[Code] ....
Intro To Computer Science C++ SAL 343 JHG 344 John Adams 111223333 100 87 93 90 90 89 91 Willy Smith 222114444 90 73 67 -77 70 80 90 Phil Jordan 777886666 100 80 70 -50 60 90 100
One more thing, I also am having problems with reading last name. If I edited the inout file and had for example John Adams Jr. it would cause huge print problems. When I remove it it prints out perfectly.
I've written a program which takes a character string and then prints each character vertically so that for instance the string 123 can be written as 1 2 3
no what i need is for all the numbers from zero to the inputted number to print the numbers digits vertically but each number to be printed horizontally so that for instance an input of 11 prints
1 2 3 4 5 6 7 8 9 1 1 0 1
i've made it so that i can print all numbers up to the inputted number vertically; however, i am stuck with a method for making each number print horizontally as described above.
/* Task: create a function that determines prime number and use it to print out prime numbers from 0-50: */
Function prototype: Should return a `bool` (because it answers a yes/no question) and should take in a single int (to ask whether it's prime).
- An int greater than 2 is prime if it is not divisible by any number between 2 and itself, not including itself. - Use this function to print out the primes less than 50. Check it against my list: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
#include <iostream> using namespace std; int prime(int&x) { if(x%2==1)
[Code] ....
It is printing out the correct prime numbers but also printing this between each number: 1629974960
for example having input "12345556asf87" we get "123456asf". I need to do this task with getchar and putchar, and the with strings. My programs aren't working
stream: char c = 0, c_ = 0; char flag = 0; while ((c = getchar()) != '.') {
I have an exercise that asks me to print numbers at random from the following set (using only a single statement):
2, 4, 6, 8, 10
Here's my statement:
Code: cout << (2 + rand() % 9) << " ";
which prints numbers at random between 2 and 10, now I can use the modulus operator in an if...else statement to print only even numbers but the exercise specifically requires using only one statement, can that be done using the conditional operator? and if not then how?