answersLogoWhite

0

If you assign -1 to a unsigned variable it will contain the biggest number its able to hold.

For example if you assign -1 to a unsigned int it will be 4294967295 as its the biggest number a unsigned int can hold.

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

Write a c or c plus plus program to print first 50 odd numbers using do while loop?

unsigned count = 0;unsigned num=1; do { std::cout << num << std::endl; num +=2; } while (++count<50);


Algorithm to find factorial using functions?

factorial using recursion style in c++ is unsigned int fact(unsigned int a) { if (a<=1) return 1; else { f*=fact(a-1); return a; } } when using looping structure factorial is unsigned int fact (unsigned int n) { unsigned int i,f=1; for(i=1;i<=n;i++) f*=i ; return f; }


Why can't you use a equals equals sign for a for statement?

This answer applies to programming languages in general. The equals sign is used for assignment. For example, the code "$variable = 1" assigns the value of 1 to the variable $variable. If you want to test whether values are the same (equality) the double equals sign is used. For example, when you want to verify that $variable has been assigned the value of 1 you would use: $variable == 1


What do you need for a valid recursively defined function?

Nothing special... here is an example: unsigned power (unsigned a, unsigned b) { if (b==0) return 1; else return power (a, b-1) * a; }


How to write a program to find the delimiter matching in stacks?

== == using recursions: unsigned int Factorial( unsigned int x) { if(x>0) { return ( x * Factorial(x-1)); } else { return(1); } } factorial: unsigned int Factorial( unsigned int x) { unsigned int u32fact = 1; if( x == 0) { return(1); } else { while(x>0) { u32fact = u32fact *x; x--; } } }

Related Questions

2 plus t7 -1?

And what is the question? - The value of such an expression will depend on the value assigned to the variable, in this case, "t".


How do you write a c plus plus recursion program to find fibonacci series?

#include<iostream> unsigned fib (unsigned term, unsigned a=0, unsigned b=1) { if (term<1) return a; return fib (--term, a+b, a); } int main() { std::cout << "Fibonacci (1000th term): " << fib (1000) << std::endl; }


What does count equals count plus 1 and total equals total plus 1 in algorithm means?

This is an instruction to increment the value of a variable by 1 (in this case, either the variable count or the variable total).


C plus plus what do you do if im stuck in an infinite loop?

There are three ways out of a loop.1. Satisfy the loop ending condition2. Execute a break statement3. Terminate the programPerhaps you are not changing the value of the variable that is used in the loop ending condition. Perhaps you are using a variable, such as an unsigned int, decrementing it, and expecting it to go negative. Suggest you run the program in a debuger and step through the loop.


Write a c or c plus plus program to print first 50 odd numbers using do while loop?

unsigned count = 0;unsigned num=1; do { std::cout << num << std::endl; num +=2; } while (++count<50);


Simplify the variable expression which is 6x plus 1 plus 7-3x.?

3x + 8


How do you find the factorial of any number?

Given an integer, n, recursively multiply by n-1 until n is 1.unsigned long long fact (unsigned long long n) {return (n>1)?n*fact (n-1):1;}Note that an unsigned long long integer of 64 bits length can only accommodate factorials up to n=21. To cater for anyinteger you will need to use a variable-length integer type. The C language does not provide one as standard, but you will find third-party libraries that can cater for huge integers, typically storing the integer as a variable-length string.


How do you find the greatest common factor in c plus plus language?

#include<iostream> #include<vector> #include<time.h> std::vector<unsigned> factors (const unsigned num) { std::vector<unsigned> vec; if (num) { for (unsigned f=1; f<num/2; ++f) if (!(num%f)) vec.push_back (f); if (num>1) vec.push_back(num); } return (vec); } bool exists (unsigned num, std::vector<unsigned>& vec) { for (unsigned index=0; index<vec.size(); ++index) if( num==vec[index] ) return( true ); return( false ); } std::vector<unsigned> intersection (std::vector<unsigned>& vec1, std::vector<unsigned>& vec2) { std::vector<unsigned> intersects; for (unsigned index=0; index<vec1.size(); ++index) if (exists (vec1[index], vec2)) intersects.push_back( vec1[index] ); return (intersects); } int main() { srand ((unsigned) time (NULL)); // repeat 10 times... unsigned repeat=10; do{ // select two random numbers (0 to RAND_MAX) unsigned num1 = (unsigned) rand(); unsigned num2 = (unsigned) rand(); std::vector<unsigned> vec1 = factors (num1); std::vector<unsigned> vec2 = factors (num2); std::vector<unsigned> common = intersection (vec1, vec2); if (common.size()) std::cout<<"The GCF of "<<num1<<" and "<<num2<<" is "<<common.back()<<std::endl; else std::cout<<num1<<" and "<<num2<<" have no common factors"<<std::endl; }while(--repeat); } Example output: The GCF of 20754 and 19236 is 6 The GCF of 29182 and 10926 is 2 The GCF of 29587 and 4089 is 1 The GCF of 9652 and 29485 is 1 The GCF of 12406 and 21097 is 1 The GCF of 15959 and 10156 is 1 The GCF of 15619 and 16111 is 1 The GCF of 4486 and 30240 is 2 The GCF of 17121 and 32223 is 3 The GCF of 30290 and 10534 is 2 Press any key to continue . . .


Algorithm to find factorial using functions?

factorial using recursion style in c++ is unsigned int fact(unsigned int a) { if (a<=1) return 1; else { f*=fact(a-1); return a; } } when using looping structure factorial is unsigned int fact (unsigned int n) { unsigned int i,f=1; for(i=1;i<=n;i++) f*=i ; return f; }


How do you generate Armstrong series in c plus plus?

#include <iostream> #include <math.h> // for std::pow() unsigned int get_length(unsigned int num,const unsigned int base=10) { unsigned int len=1; while(num && (num/=base)) ++len; return( len ); } bool is_armstrong(const unsigned int num,const unsigned int base=10) { unsigned int len=get_length(num,base); unsigned int sum=0; unsigned int tmp=num; while(tmp) { sum+=(unsigned int)std::pow((double)(tmp%base),(double)len); tmp/=base; } return(num==sum); } int main() { std::cout << "Armstrong series (base 10):"; for(unsigned int num=0; num<=0xffffffff; ++num) if(is_armstrong(num)) std::cout << " " << num; std::cout << std::endl; return(0); }


What is programme in c plus plus of a Armstrong number?

#include <iostream> #include <math.h> // for std::pow() unsigned int get_length(unsigned int num,const unsigned int base=10) { unsigned int len=1; while(num && (num/=base)) ++len; return( len ); } bool is_armstrong(const unsigned int num,const unsigned int base=10) { unsigned int len=get_length(num,base); unsigned int sum=0; unsigned int tmp=num; while(tmp) { sum+=(unsigned int)std::pow((double)(tmp%base),(double)len); tmp/=base; } return(num==sum); } int main() { std::cout << "Armstrong series (base 10):"; for(unsigned int num=0; num<=0xffffffff; ++num) if(is_armstrong(num)) std::cout << " " << num; std::cout << std::endl; return(0); }


What is 9x squared plus 6x plus 1?

You can calculate a value if you assign a value to variable "x".