Difference between perfect square and a number that can be expressed as product of consecutive integers:

Image
A perfect square is a number that can be expressed as the product of an integer by itself or as the second exponent of an integer¹. For example, 1, 4, 9, and 16 are perfect squares because they are the squares of 1, 2, 3, and 4 respectively. A perfect square can also be written as x^2, where x is an integer. A number that can be expressed as a product of consecutive integers is a number that can be obtained by multiplying two or more integers that follow each other in order. For example, 6, 24, and 120 are numbers that can be expressed as products of consecutive integers because they are equal to 2 x 3, 2 x 3 x 4, and 2 x 3 x 4 x 5 respectively. A number that can be expressed as a product of consecutive integers can also be written as x(x + 1)(x + 2)...(x + n), where x and n are integers. The difference between a perfect square and a number that can be expressed as a product of consecutive integers is that a perfect square has only one factor pair that consists of the same integer, whi

C programing Lesson 1:





Following are the few basic concept that must be understand before writing a program in C programing language.

The C Character Set:
                                   A character denotes any alphabet, digit or special symbol used to represent information.

Variables And Constant:
                a variable is an entity that may change, whereas constant is an entity that does not change. In any C program we typically do lots of calculations. The results of these calculations are stored in computer’s memory. Like human memory, the computer’s memory also consists of millions of cells. The calculated values are stored in these memory cells. To make the retrieval and usage of these values easy, these memory cells (also called memory locations) are given names. Since the value stored in each location may change, the names given to these locations are called variable names.
Consider the memory locations shown in Figure 1.3. Here 3 is stored in a memory location and a name x is given to it. Then we have assigned a new value 5 to the same memory location x. This would overwrite the earlier value 3, since a memory location can hold only one value at a time.



Since the location whose name is x can hold different values at different times x is known as a variable (or a variable name). As against this, 3 or 5 do not change, hence are known as constants. In programming languages, constants are often called literals, whereas, variables are called identifiers. 

Rules for Naming a variable in C:

(a) A variable name is any combination of 1 to 31 alphabets, digits or underscores. Some compilers allow variable names whose length could be up to 247 characters. Still, it would be safer to stick to the rule of 31 characters. Do not create unnecessarily long variable names as it adds to your typing effort.

(b) The first character in the variable name must be an alphabet or underscore ( _ ).

 (c) No commas or blanks are allowed within a variable name.

 (d) No special symbol other than an underscore (as in gross_sal) can be used in a variable name. 

Ex.: 
si_int,  m_hra , pop_e_89 

Since, the maximum allowable length of a variable name is 31 characters, an enormous number of variable names can be constructed using the above-mentioned rules. It is a good practice to exploit this abundant choice in naming variables by using meaningful variable names. Thus, if we want to calculate simple interest, it is always advisable to construct meaningful variable names like prin, roi, noy to represent Principle, Rate of interest and Number of years rather than using the variables a, b, c. The rules for creating variable names remain same for all the types of primary and secondary variables. Naturally, the question follows... how is C able to differentiate between these variables? This is a rather simple matter. C compiler is able to distinguish between the variable names by making it compulsory for you to declare the type of any variable name that you wish to use in a program. This type declaration is done at the beginning of the program. Examples of type declaration statements are given below.

Ex.:
 int si, m_hra ; float bassal ; char code ;

C Keywords:

Keywords are the words whose meaning has already been explained to the C compiler (or in a broad sense to the computer). There are only 32 keywords available in C. Figure 1.5 gives a list of these keywords for your ready reference. A detailed discussion of each of these keywords would be taken up in later chapters wherever their use is relevant.


The keywords cannot be used as variable names because if we do so, we are trying to assign a new meaning to the keyword, which is not allowed. Some C compilers allow you to construct variable names that exactly resemble the keywords. However, it would be safer not to mix up the variable names and the keywords. Note that compiler vendors (like Microsoft, Borland, etc.) provide their own keywords apart from the ones mentioned in Figure 1.5. These include extended keywords like near, far, asm, etc. Though it has been suggested by the ANSI committee that every such compiler-specific keyword should be preceded by two underscores (as in __asm ), not every vendor follows this rule

 



Comments

Popular posts from this blog

CP Open ended Lab:

C language program to find prime number

What is a computer language