I will explain in the easiest way the difference between the function and recursive function in C language. Simple Answer is argument of the function is differ but in the recursive function it is same:) Explanation: Function int function(int,int)// function declaration main() { int n; ...... ...... n=function(a,b); } int function(int c,int d) { ...... ...... ...... } recursive Function: int recursive(int,int)// recursive Function declaration main() { int n; ..... ..... ..... ..... n=recursive(a,b); } int recursive(int a,int b) { ..... .... .... .... } Carefully see, In the recursive Function the function arguments are same.
Code example:/* ******************************************************************************** * FUNCTION: bIsAPrime ******************************************************************************** * AUTHORS: * Flaun * * DESCRIPTION: * Finds if a given number is a prime number. * * PARAMETERS: * uiTestNumber: An unsigned integer to test. * * RETURNS: * bTRUE or bFALSE ******************************************************************************** */ #define bTRUE 1 #define bFALSE 0 #define iNO_REMAINDER 0 #define bIS_ODD(uiNumber) ((uiNumber) & 1) typedef int BOOL BOOL bIsAPrime( unsigned int uiTestNumber) { /* 4 is the first non prime number. */ if(uiTestNumber > 3) { /* The only even prime number is 2. */ if(!bIS_ODD(uiTestNumber)) { return bFALSE; } else { /* The only numbers left to divide against are 3, 5 and 7. */ /* All numbers that are divisible by a number > 7 are divisible */ /* by a number < 8. */ unsigned int uiDivisor = 0; for(uiDivisor = 3; uiDivisor
Assuming it is an unsigned int (i.e. no negatives) it would be 11111111111 which is 2047. Another way to think about it is 11bits can represent 2048 different values, and since it starts at 0 that would be 2048 - 1 which is 2047.
i=0; do{ i++; }while(i<10);
whatever the variables we declare in function signature to receive the arguments at the calling that are known as parameters.. e.g. int sum(int a,int b); here a & b are known as parameters.....
The value range. Example for 16-bit integers: signed: -32768..32767 unsigned: 0..65535
There are far more than 4 integral types in C++. As of C++11, there were 27 integral types: bool char signed char unsigned char wchar_t char16_t char32_t short signed short unsigned short short int signed short int unsigned short int int signed int unsigned int long signed long unsigned long long int signed long int unsigned long int long long signed long long unsigned long long long long int signed long long int unsigned long long int
A signed int can take a value between -32768 to 32767 and an unsigned int can take a value 0 to 65535.
Unsigned int does not have a sign, meaning that it can be zero or a positive number in the range of data type (int). Signed data has a sign and can be positive, zero or negative.
A type modifier changes the default variable type to the other possible type. An int is signed by default and may be made unsigned int a; unsigned int b;
For example 'int' is a data-type, 'short', 'long', 'signed' and 'unsigned' are modifiers, 'extern', 'auto', 'static', 'register' are storage-classes. The declarations go like this: storage-class modifiers data-type identifier example: static unsigned short int x;
signed char unsigned long int void *
There are four modifiers in C++: long, short, signed and unsigned. They are used to modify primitive types (int, char, float and double) to change their behaviour. If no type is specified, int is assumed. Thus a long long turns a 32-bit integer into a 64-bit integer while unsigned ensures an integer is always in the positive range.
Well, uh, const unsigned int and const signed int..
There are five type modifiers in C++: long short signed unsigned [] - the array subscript The first four are used solely to modify the characteristics of the int type. Signed and unsigned can also be applied to the char and wchar_t types while long can also be applied to a double. If no type is specified, int is assumed. The array subscript modifier can be applied to any type including modified types and pointers to a type. Excluding arrays, pointers and the built-in bool type, C++ has the following fundamental (built-in) types: char signed char unsigned char wchar_t signed wchar_t unsigned wchar_t int signed int unsigned int short int signed short int unsigned short int long int signed long int unsigned long int long long int signed long long int unsigned long long int float double long double A plain (unmodified) char may be signed or unsigned (implementation defined) but must behave exactly as an explicitly signed or unsigned char would. However, all three are deemed separate types in C++. Similarly with wchart_t. However, an int is implicitly signed. The length of each fundamental type is implementation defined, but can be found by using the sizeof operator either upon the type itself or upon an instance of the type. The standard library <type_traits> header can be used to determine other information, particularly useful in static (compile-time) assertions. The C++ standard library also provides additional types of specific size, including int8_t, int16_t, int_32_t, int64_t, uint_8_t, uint_16_t, uint32_t and uint64_t. Note that the _t suffix is often used to denote that a type is really a typedef (an alias) for a modified type, such as size_t (an unsigned int). However wchar_t is typically implemented as a built-in type. All fundamental types can be found in <cstddef> (which is usually included when you include any standard library header such as <iostream>) while the fixed-length integers can all be found in <cstdint>.
The primitive data types in C include:[signed|unsigned] char[signed|unsigned] short[signed|unsigned] int[signed|unsigned] long[signed|unsigned] long longfloatdoublelong doubleEnumerations (enum) and arrays may also be considered to be primitive types.
#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); }