C++ :: Program Read In 15 Integers From User Then Store And Print Out Numbers
Apr 29, 2014I want to write a program to read in 15 integers from the user, and then store them in a 5x3 array, and print out the numbers as a 3x5 array.
View 7 RepliesI want to write a program to read in 15 integers from the user, and then store them in a 5x3 array, and print out the numbers as a 3x5 array.
View 7 RepliesMy C programming class wants us to write a program to read integers into an array, sort the numbers and print out the occurrence of each number. I've tried everything that I can think of but the core dump is still occurring.
void countValues ( FILE *inf, int list[], int size ); /* Function prototypes. */
void printFrequencies( const int list[], int size );
int main (void) {
int status = EXIT_SUCCESS; /* defaulting status to success. */
FILE *inf = fopen( "numbers.txt", "r" ); /* input data file */
[Code] .....
write a program in c to read a sequence of N integers and print the number that appears the maximum number of times in the sequence.
View 1 Replies View RelatedI'm a beginner at c++ and I need to write a program that reads a set of integers and then finds and prints the sum of the even and odd integers. The program cannot tell the user how many integers to enter. I need to have separate totals for the even and odd numbers. what would I need to use so that I can read whatever number of values the user inputs and get the sum of even and odd?
View 2 Replies View RelatedI tried to work on this program for while, but I am not able to get it to work
Directions:Write a program that reads an integer n from the user.
Display the first 100 numbers, with newlines every n numbers, using % operator
#include <stdio.h>
int main(void){
int a = 0;
int b = 99;
printf("Enter a number: ");
scanf ("%d", &a);
[Code] ....
When I run this code it asks me to enter a number. It doesn't matter what number I enter it gives me the numbers from 1 to 100 in one horizontal line.
I want this program to do something like this:
for example if the user enters n=6 the program should give:
0 1 2 3 4 5 6
7 8 9 10 11 12 13
and so on
I am trying to Write a program that inputs three integers from the keyboard and prints the sum, average, product, smallest and largest of these numbers. How do i go about it. What i dont know is how to come up with smallest and largest number .
View 1 Replies View RelatedMy program is designed to read input from the user and then store that input in a structure variable. Whenever i use the cin.getline() function, it comes up with a semantic issue. Here is the code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int DESCRIPTION_SIZE = 100, DATE_SIZE = 20;
struct inventory {
string description[DESCRIPTION_SIZE];
[Code] .....
I left out the other functions. The error reads "no matching member function for call to 'getline'.
I have to complete a project that i want to read float numbers from keyboard and store them into an array of 10 elements.! Every time that a number stored into array i want to compare with previous one if they have +-10 difference .. I want to keep only 10 elements into my array so every time that i give value a[0] replace a[1], a[1] replace a[2],a[2] replace a[3]. . . .and a[10] deleted.. So when all elements of the array are similar with +-10 values print out the array.!
View 1 Replies View Relatedso basically my project goes like this:
Write a C++ program that reads in two positive integers that are 20 or fewer digits in length and outputs the sum of the two numbers.
Your program will read the digits as values of type char so that the number 1234 is read as four characters '1', '2', '3' and '4'. After they are read into the program, the characters are changed to values of type int. The digits will be read into a partially filled array and you might find it useful to reverse the order of the elements in the array after array is filled with data from the keyboard.
Your program will perform the addition by implementing the usual pencil and paper addition algorithm. The result of the addition is stored in an array of size 20 and the result is written to screen. if the result of the addition is an integer with more than maximum number of digits(that is more than 20 digits) then your program should issue a message saying that it has encountered "integer overflow".
You should be able to change the maximum length of the integers by changing only one globally defined constant. Include the loop that allows the user to continue to do more additions until the user says the program should end. What I have so far is
#include <iostream>
#include <cstdlib>
using namespace std;
void reverseArr(int a[], int liu);
void addLargeInt(int a1[], int liu1, int a2[], int liu2, int sum[], int& liu_sum);
int main() {
cin.get(next);
[Code]...
create a program that asks the user to input 10 integers of an array the program will add the numbers greater or equal to 10.
View 6 Replies View Related1. Construct a class diagram that can be used to represent food items. A type of food can be classified as basic or prepared. Basic food items can be further classified as meat, fruit, veg or Grain. The services provide by the class should be the ability to enter data for new food, to change data for food and to display existing data about food.
using this class definition write a main program to include a simple menu that offers the following choices:
1. Add food
2. Modify Food
3. Delete Food
4. Exit this menu
2. Read a list of numbers from a file and then print them out in reverse order. State whether the list is palindromic or not.
The question is "Write a program that uses a while loop to read a set of integers from an input file called "data.txt" and prints the total number of even numbers read from the file."
Code below is the program I have created so far. I keep getting the window to pop up but not stay up so I am assuming I am doing something wrong.
#include <iostream>
#include <fstream>
using namespace std;
int main() {
std::fstream input("data.txt");
if (!input.is_open()) {
std::cout << "There was an error opening data.txt";
[Code]...
I know it would be easier to create an int array, but I want the program to create integers as the user requests. For example, if the user enters 4, the program creates 4 integers with the names input. Each integer is better as an individual integer, not an element in an array.I'm not sure if this is a possibility with C++.
View 3 Replies View RelatedThis is the problem :- Write a program that keeps reading integers until user enters -1, then it prints the maximum and the minimum among all numbers (-1 should be ignored).
View 14 Replies View RelatedWrite a program that asks the user to type 10 integers of an array. The program will then display either "the array is growing", "the array is decreasing", "the array is constant", or "the array is growing and decreasing."
(Hint: compare consecutive numbers in array and check whether it is increasing or not or constant) I wrote the program very well, but do I have to use "bool" like in c++ ? I haven't known how to code in c++ yet.So, I don't want to use "bool" in C.
I also wrote code about it but it looks like backslash and one,two,three,four,five how can I do it like this ?
This is in c. Write a program which asks for X numbers, and stores them in an array.
The program then asks the user to enter a number to look for, and tells the user how many times that number appears in the array of numbers (if any), and the array index which contain the number
Make an array of the indexes where the number was found, and then format your output to match my output.
Sample Run:
How many numbers would you like to enter: 5
Please enter a number:1
Please enter a number:2
Please enter a number:3
Please enter a number:4
Please enter a number:2
The numbers you enter were: 1, 2, 3, 4, 2
Please enter a number to find: 2
The number appears 2 times, at array ellements with indexes 1, 4
Press any key to continue . . .
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!
[Code]...
Write a C program that takes multiple integers from the user and finds the minimum value. The numbers entered by the user are positive integers. When the user is done entering all the numbers, the user enters the sentinel value of -1.
This is a sample output. Notice how the program prints a counter (1, 2, 3, ) for user keep track of how many numbers were entered so far. Include this feature in your program.
I have tried different ways to get the result from while loops, do while, and if-else statements. We have not done any max/min problem in class and the book was kind of vague. We have not learned arrays yet in class and I can't figure a way to compare the integers the user inputs as it is an infinite(from what I am reading) amount aloud. The problem I am seeing is the loop works and stops with the sentinel value but the INT_MIN is using the sentinel value. I also have not addressed the input of negative numbers yet with the first program I wrote, maybe one of my problems.
Code:
/*File:HW2Q3.c,
A C program that takes multiple integers from the user and finds the minimum value. The numbers entered by the user are positive integers. When the user is done entering all the numbers, the user enters the sentinel value of -1.*/
/*header files*/
#include<stdio.h>
#include<limits.h>
/*****start program*****/
int main() {
[Code] ....
I have also tried this way as well, min value still comes back as -1 the sentinel value, and the else statement is being ignored. I am sure it is something silly but I am lost and confused at this point.
Code:
/*File:HW2Q3.c,
A C program that takes multiple integers from the user and finds the minimum value. The numbers entered by the user are positive integers. When the user is done entering all the numbers, the user enters the sentinel value of -1.*/
/*header files*/
#include<stdio.h>
#include<limits.h>
[Code] ....
The problem deals with writing a program to geta series of integers from a user and storing those values into an array. Then use a function called selection_sort, when given an array with n elements, the function must sort the array from smallest to largest values.
I have code, and im trying to get it to compile but im getting these implicit declaration errors and conflicting types. Here is my code and the compiler errors.
Code:
Compilation started at Sun Feb 10 20:14:48
gcc -Wall -o ex9-1 ex9-1.c
ex9-1.c: In function 'main':
ex9-1.c:16:5: warning: implicit declaration of function 'selection_sort' [-Wimplicit-function-declaration]
ex9-1.c:20:2: warning: implicit declaration of function 'prinf' [-Wimplicit-function-declaration]
ex9-1.c: At top level:
[Code] ...
Compilation exited abnormally with code 1 at Sun Feb 10 20:14:49
Code:
#include <stdio.h>
int main(void) {
int a[100], i, j, N;
printf("How many numbers will you be entering: ");
scanf("%d", &N);
[Code] .....
Write a program which stores 10 decimal numbers in an array. For these numbers accept input from the users. Once the array is populated do the following:
Display each elements of the array
Display the sum of all the elements of array
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 ....
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] ....
Objective of this program is to read binary data from a file and print it.
Code:
#include <stdio.h>
void readFile(void);
int main(){
readFile();
return 0;
[Code] .....
But When I Run This Code First It Print "Error." Then Rest Of The File.Say In My File I Have "I AM HUMAN", It Prints "Error. HUMAN"!!
I Cant Figure Out Whats Wrong In The readFile() Function.It seems right to me.
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] ....
Basically this is what i need to do. Write a program that reads a number from the keyboard, separates it into its individual digits and prints the digits to screen, each on its own line followed by the same number of stars as itself.
For example, if the number is 2339 the program should print
9 *********
3 ***
3 ***
2 **
So far i have managed to separate the number and have them on different lines, but how to implement the stars onto each line with the number!
My code so far:
int main() {
int n;
printf("number? ");
scanf("%d", &n);
while (n > 0) {
printf("
%d
[Code]...
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?