C :: Finding Positive / Negative Integers Unsigned Can Hold

Jan 25, 2013

Consider a new data type, the mikesint, which can hold 9 bits.

(a) What is the largest integer that an unsigned mikesint can hold?
(b) What is the largest positive integer that a signed mikesint can hold?
(c) What is the largest negative integer that a signed mikesint can hold?

Not sure how to determine this. I'm stuck.

View 5 Replies


ADVERTISEMENT

C++ :: Positive And Negative Infinity

May 2, 2013

What are positive and negative infinity for different data types in c++, are they represent maximum and minimum limit of a type? or positive infinity is not a finite value.can some explain this positive and negative infinity paradigm

View 3 Replies View Related

C :: Unsigned Int Leads To Big Positive Number

Oct 29, 2014

I was going through the following statement in a c book:

"interpreting -1 as unsigned int leads to a big +ve number"

-1 is already unsigned .... then what does the above statement mean ??

View 3 Replies View Related

C++ :: Positive Remainders Returning Negative?

Nov 26, 2013

int Fib1 = 1;
int Fib2 = 2;
int Fib3 = 0;
int randomynumber;
int Loop;

[code].....

this returns negative numbers sometimes.what did i do wrong side note this is not the complete program it is only the part with the problem because the complete code is sort of longish and very confusing

View 2 Replies View Related

C/C++ :: Counting Positive And Negative Numbers?

Jan 27, 2014

#include <iostream>
using namespace std;
int initialization (int []);
int identifying (int [],int);

[Code].....

View 8 Replies View Related

C++ :: Display Count Of Positive And Negative And Zero Entered

Aug 18, 2014

Write a program to enter the number till 100 till the user want and at the end it should display the count of positive and negative and zero entered.

View 8 Replies View Related

C :: Why Program Can't Subtract Negative Number From Positive One

Feb 2, 2015

My program uses a while loop to eventually get to an error of zero and a root of sqrt(3). I'm not understand why after the third iteration the program fails to compute a new x value. I'm using Visual Studio 2013. The code tag instructions were dubious.

Code:

#include <stdio.h>
#include <math.h>
main() {
/*This program uses the Newton-Raphson method to solve y = (x^3)-3 for it's roots.*/
printf("This program uses the Newton-Raphson method to solve y = (x^3)-3 for it's roots. Enter your estimate of the root.
");
float x,y,z;
int num;
num = 0;

[Code]...

View 1 Replies View Related

C++ :: How To Extract Positive Integer From Unsigned Char Array

Jan 13, 2015

I have an embedded microcontroller system communicating with a similar system by radio. The api for the radio requires data to be transmitted as an unsigned char array. It will always transmit a positive integer in the range 0 to 255.When I receive the data I am having difficult in extracting this positive integer.

Code:
unsigned char rxData[4]={'1','2','3',''};
int inVal=0;

//want to assign inVal whatever number was transmitted

E.g. 123

I've been at this for a week and have tried at least 10 different approaches including the use of the atoi(), copying the absolute value of each element of rxData into another char array, reinterpret_cast, and others.

View 13 Replies View Related

C++ :: If Statement To Read Number Negative Or Positive Not Working

Nov 10, 2014

So I tried creating a test code for reading a negative number and positive number but whenever I enter a negative number it read it as being positive.

#include <stdio.h>
#include <iostream>
#include <iomanip>

[Code].....

PS: I am using char over int because the program that I am testing for requires me to use 8 bit variable.

View 2 Replies View Related

C/C++ :: Transfer Array Values To Positive And Negative Arrays?

Oct 21, 2014

I have a problem with my assignment. I would like to ask how to transfer positive and negative values from array temperature to arrays positive and negative?

#include <iostream>
#include <iomanip>
using namespace std;
int main(){
int n=0, d=0, temperature[20], sum;
int positive[], negative[];
float avg;

[code]....

View 5 Replies View Related

C :: How To Stop User From Inputting Negative Number Into Unsigned Long

Feb 3, 2013

here's one more thing id like to do to make the input even better able to handle user error, but im not sure if its possible or at least easy. I need the function to return a large positive number. As of right now, it can handle users entering characters, but what if the user enters a negative number? is there a way to check to see if what is coming in is negative before the sign gets lost in conversion to unsigned"ness"?

Code:
unsigned long getNum(char prompt[80])
{
unsigned long darts;
printf("%s", prompt);
while((scanf("%lu", &darts)) != 1)
{
[code]....

View 3 Replies View Related

C :: Program To Show Highest Negative And Lowest Positive Temperature Of Year

Jan 19, 2014

I have an assigment and I don't know yet how to write this program :" I introduce the average monthly temperatures of a year(12 values for 12 months). When I compile the program it needs to show the highest negative temparature and the lowest positive temperature of that year.

Example: Entry data: -4 -6 0 5 10 20 24 25 17 8 -1 -7 exit data : max negative= -1 and min positive= 5 "

View 11 Replies View Related

C++ :: User Input - Calculate Sum Of Only Positive Values While Ignoring Negative Numbers

Jun 19, 2014

So I have to make a program that allows the user to enter both positive and negative numbers and the program is suppose to calculate the sum of only the positive values while ignoring the negative values. Also it is to be a sentinel-controlled loop with a number ending the set of values.

View 4 Replies View Related

C :: Declare Two 1-dimensional Parallel Arrays Of Integers That Will Hold The Information Of Up To 10 People

Jul 30, 2014

In pseudocode and in C code, declare two 1-dimensional parallel arrays of Integers to store the age and weight of a group of people that will hold the information of up to 10 people. Use a For loop to iterate through the array and input the values. This is the code i have, but my array is showing up as 11 and not 10?

Code:
#include <stdio.h>
int main() {
//Define Variables
float Age_Data[10],Weight_Data[10];
float Age_Input,Weight_Input;

[Code] .....

View 3 Replies View Related

C++ :: The Value Of 8 Bytes For Unsigned Integers

Jan 26, 2014

I'm confused about the actual value of 8 bytes for unsigned integers.

The below code suggests the value is 13217906525252912201:

#include <stdio.h>
#include <inttypes.h>
typedef uint64_t byte_int_t;
int main(void){
byte_int_t t;
printf("%" PRIu64 "
", t);
}

./runprogram
13217906525252912201

However, when I use a calculator, I get a different value: 2^64= 1.8446744e+19

So I was wondering is this really 8 bytes? So I try below test and it produces 8, as expected:

#include <stdio.h>
#include <inttypes.h>
typedef uint64_t byte_int_t;
int main(void) {
byte_int_t t;
printf("%u
", sizeof(t));
return 0;
}

So why does C and my calculator provide two different results?

View 1 Replies View Related

C :: Function For Raising Numbers To Positive Integers

Sep 18, 2013

Write a function that raises an integer to a positive integer power. Call the function x_to_the_n taking two integer arguments x and n. Have the function return a long int, which represents the results of calculating x^n.Here's my code:

Code:

#include <stdio.h>
long int x_to_the_n(int x, int n)
{
int i;
long int acc = 1;

for(i = 1; i <= n; ++i)
acc *= x;
}

[code]...

It compiles OK, but when I run it the program stops after entering the number (x) and power (n).

View 2 Replies View Related

C/C++ :: Compute Sum And Average Of All Positive Integers Using Loop

Oct 8, 2014

I got an assignment which asked me to create a program that asks user to input 10 numbers (positive and negative) integer. The program would be using loop to compute sum and average of all positive integers, the sum and average of negative numbers and the sum and average of all the number entered. But, the new problem is after I've entered all the number, the answer that the program gave me wasn't the answer that the program supposed to give. I don't know how to describe it, I would attach a picture and the code below:

#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
//Declaration
int x, value, sum, average, SumPositive, SumNegative, Positive, Negative;
float AveragePositive, AverageNegative;

[Code] .....

View 12 Replies View Related

C :: Entering Two Positive Integers To Multiply Together - Program Won't Compile

Aug 24, 2013

I'm trying to get my C program to compile but it's not working at all. I've programmed a little in C++ before but I'm not used to C. Here's my program so far:

Code:
int main(void){
// Establishes variables
int num1, num2, product;
float quotient;

[Code] .....

It keeps giving me an error message as follows:

"/usr/bin/ldrelabwk2: file format not recognized; treating as linker script
/usr/bin/ldrelabwk2:1: syntax error
collect2: ld returned 1 exit status"

View 11 Replies View Related

C++ :: Reading Integers Out Of A Text File And Only Adds Positive Ones?

Sep 26, 2014

I'm basically trying to make a simple program that reads integers out of a text file and only adds the positive ones and not the negatives.

All is well except it won't take the last integer (the last line, I presume.) I took the negative out, nothing to do with that. I put more numbers in and I made the txt file less, no answer. No matter what the last number is, the program won't read it. I've been researching online and I've been seeing that it might be an issue with "while "!inFile.eof())".

Anyway here's the program:

#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream inFile;
ofstream outFile;

[Code] .....

Here's the txt file:
5
6
-9
21
3

I'm always getting 32 for some reason.

View 2 Replies View Related

C/C++ :: Conversion Of Negative Integers To String Without Using Atoi Function

Sep 21, 2014

char intToStr(int a) {
int n, i, j, sign, set;
char r[10], s[10];
if (a[0] == '-')
sign = -1;
if (sign == -1)

[Code] ....

I have doubt at the time of handling of negative numbers at the time of converting to string ....

View 2 Replies View Related

C++ :: Reads In Two Positive Integers That Are 20 Or Fewer Digits In Length - Output Sum?

May 1, 2013

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.

For some reason the sum won't add or output though, This is what i have so far:

#include <iostream>
using namespace std;
const int MAXIMUM_DIGITS = 20;
void input_Large_Int (int a[], int& size_of_A); //input function for the two big integers
void output_Large_Int(int a[], int size_of_A); //output function for the two big integers and the sum integer
void add(int a[], int size_of_A, int b[], int size_of_B, int sum[], int & size_Sum); //add function for the big integers' sum

[Code] .....

View 1 Replies View Related

C++ :: Create A File And Fill 6x6 Array With Random Positive Integers

Nov 24, 2014

This is my code!! but it's not working at all.

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main () {
ofstream fout("datain.txt",ios::out);
int array[6][6];

[Code] .....

View 5 Replies View Related

C++ :: Write Negative To One File And Positive Numbers To Another File

Dec 11, 2013

im supposed to create a program that reads in a list of integers from the terminal and writes the negative numbers to one file and the positive numbers to another file.

i got most of it doen but for some reason its not writting the negative numbers. on what im doing wrong?

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
int pos_num = 0;
int neg_num = 0;
int positive_numbers = pos_num % 5;

[Code]...

View 2 Replies View Related

C++ :: Average Negative / Positive Numbers And Total Average?

Nov 18, 2013

I am trying to average the negative numbers and positive number and of course the total average.

This will read in a list of n values, where n is not known ahead of time. The number of values read into the array will be saved in n.

vector<int> readList() {
std::vector<int> result;
ifstream inFile;
inFile.open("setA.txt");
for (int x; inFile >> x; ) {
result.push_back(x);

[code]....

array is a one-dimensional array of integers and n is the number of elements in that array that contain valid data values. Both of these are input parameters to the function. The function must calculate 1) the average of the n integers in array, storing the result in ave; 2) the average of the positive numbers (> 0), storing the result in avePos, and 3) the average of the negative numbers (< 0), storing the result in aveNeg.

void avgs (std::vector &array, int &ave, int &avePos, int &aveNeg) {
int sum = 0, pos_sum = 0, neg_sum = 0, pos_count = 0, neg_count = 0;
for (auto i : array) {
sum += i;
if (i > 0) { pos_sum += i; ++pos_count; }

[code]....

View 1 Replies View Related

Visual C++ :: Ignoring Negative Numbers When Trying To Add Only Positive Numbers?

May 15, 2013

ignoring negative numbers when I am trying to add up only positive numbers.

SAMPLE:
if (num>=0) {
sum= sum + num;
}
else

how would the else in this case being a negative number not be included in the sum

View 4 Replies View Related

C++ :: Read Two Positive Integers That Are 20 Or Fewer Digits In Length And Output Sum Of Two Numbers

Apr 30, 2013

so 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]...

View 2 Replies View Related







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