Search Here

What We Share With You !!!

All About Programming, Learn About Programming, Programming Tutorials For Beginners, All About Flowchart, Programming Tutorials, Problems Solving, Error Solving, Programming Examples Free, Programming Task, Install Guide, E-Books, Useful Commands, Compilers, For Windows, For Ubuntu, Programming Courses, Programming Exams, Increase Programming Logic, Syntax, Flow, Functions, Soft Installation Guide, Free Tutorials & Courses, etc.

Contact Me

Ticker

6/recent/ticker-posts

Categories

Recent Post

Pages

How to Improve Logic Building Skill - Tips to Improve Logic Building Efficiency

 What is logic building in programming?

In programming, the process of creating an organized method for resolving issues through a sequence of logical procedures or algorithms is known as logic building. It entails approaching the issue at hand with critical thought, dissecting it into more manageable chunks, and then creating a series of steps (or code) to carry out the intended action. Logic construction is a fundamental programming ability that underpins everything from simple scripts to sophisticated software systems. By honing this talent, programmers can write more effective, efficient, and dependable code. The points below are very important in logic building. If you follow these points consistently make sure you will be a master in programming.

what is logic building in programming

How to Improve Your Logic-Building Skills in Programming?

Improving your logic-building skills in programming is critical for producing efficient, effective, and maintainable code. Here are some ideas to help you improve these talents.

Key Features of Logic Building in Programming

  1. Analysis of problem
  2. Start Designing algorithms
  3. Find the solutions to problems
  4. Learn the flow control of the program
  5. Learn techniques to handle errors
  6. Increase Problem-solving ability
  7. Write codes logically

Tips to Improve Logic Building Efficiency

  1. Regular Practise: Engage in coding exercises, puzzles, and challenges that require logical reasoning.
  2. Learn Standard Algorithms and Data Structures: Learn about common algorithms and data structures, which are the foundation for programming logic.
  3. Start Work on Real-World Projects: Apply your logic-building abilities to real-world problems, which can present more complicated and diverse obstacles than textbook examples.
  4. Check and Update Code: Regularly evaluate and refactor your code to increase clarity and performance.

Every Beginner Should Need to Learn These Logic Building Programs

Here are some crucial logic-building programs that are required for establishing good problem-solving skills in programming:
  1. Check Palindrome
  2. Creating Fibonacci Series
  3. Find Prime Number
  4. Factorial Calculations
  5. Sorting Techniques Algorithms
  6. Binary Search
  7. Array (Rotation, Reversal, Sorting, and Modification)
  8. String Reversal
  9. Pattern Printing (Star/Numerical)
  10. GCD of Numbers
  11. Matrix Operations
  12. Linked List Operations


Download Source Files


You will become a better developer after your logic building is strong. Once you acquire good coding skills, you will get many new opportunities.

Chapter 2.4 - Discuss How Variables Are Used In A Program | Part - 3


DECLARATION OF STORAGE CLASS

Variables in C can have not only data type but also storage class that provides information about their location and visibility. The storage class decides the portion of the program within which the variables are recognized. Consider the following example:


             Download Turbo C++ Program Program Complier                                                                                    

DECLARATION OF STORAGE CLASS

/* Example of storage classes */
int m;                                 
main()                                
{                                          
     int i;                            
    float balance;          
.....                          
.....                          
     functions1();            
}                                        
             function1()                        
{                                         
int i;                       
  float sum;               
.....                          
.....                          
}            


The variable m which has been declared before the main is called a global variable. It can be used in all the functions in the program. It need not be declared in the functions. A global variable is also known as an external variable. 

           C Numbers Pattern Programs With Easy Solutions

           C Star Pattern Programs With Easy Solutions
                  
The variables i, balance and sum are called local variables because they are declared insides a function. Local variables are visible and meaningful only inside the functions in which they are declared.

They are not known to other functions. Note that the variable i has been declared in both the functions. Any change in the value of i in one function does not affect its value in the other.       
C provides a variety of storage class specifiers that can be used to declare explicitly the scope and lifetime of variables. The concepts of scope and lifetime are important only in multifunction and multiple file programs and therefore the storage classes are considered in detail later when functions are discussed. For now, remember that there are storage class specifiers (auto, register, static and extern) whose meanings are given in Table 2.10.

The storage class is another qualifier (like long or unsigned) that can be added to a variable declaration as shown below:

auto int count;        
register char ch;      
static int x;           
extern long total ;  

Static and external (extern) variables are automatically initialized to zero. Automatic (auto) variables contain undefined values (known as 'garbage') unless they are initialized explicitly.


DECLARATION OF STORAGE CLASS


Chapter 2.4 - Discuss How Variables Are Used In A Program | Part - 2


User-Defined Type Declaration


C supports a feature known as "type definition" that allows users to define an identifier that would represent an existing data type. The user-defined data type identifier can later be used to declare variables. It takes the general form. 

typedef type identifier;
Where type refers to an existing data type and "identifier" refers to the 'new" name given to the data type. The existing data type may belong to any class of type, including the user-defined ones. Remember that the new type is 'new' only in name, but not the data type. typedef cannot create a  new type. Some examples of type definition are:

typedef int units;     
typedef float marks;

Here, units symbolize int and marks symbolizes float. They can be later used to declare variables as follows:

units batch1, batch2;               

batch1 and batch2 are included as int variable and name1[50] and name2[50] are declared as 50 element floating point array variables. The main advantage of typedef is that we can create meaningful data type names for increasing the readability of the program.
Another user-defined data type is an enumerated data type provided by ANSI standard. It is defined as follows: 

enum identifier {value1, value2....valuen};

The "identifier" is a user-defined enumerated data type which can be used to declare variables that have one of the values enclosed within in braces (known as enumeration constants). After this definition, we can declare variables to be of this 'new' type as below:

enum identifier v1, v2,....vn;

The enumerated variables v1,v2....vn can only have one of the values value1, value2,...valuen. The assignments of the following types are valid:


v1 = value3;
v5 = value1;

An example:

enum day {monday, Tuesday,...Sunday};
enum day week_st, week_end;                 
week_st = Monday;                                   
week_end = Friday;                                   
if(week_st == Tuesday)                              
week_end = saturday;                                   

The compiler automatically assigns integer digits beginning with 0 to all the enumeration constants. That is, the enumeration constant value 1 is assigned 0, value2 is assigned 1, and so on. However, the automatic assignments can be overridden by assigning values explicitly to the enumeration constants.



             C Programming Star Pattern Programs     

For example:


enum day {Monday = 1, Tuesday,....Sunday};

Here, the constants Monday is assigned the value of 1. The remaining constants are assigned values that increase successively by 1.
The definition and declaration of enumerated variables can be combined in one statement.

Example:

enum day {Monday,......Sunday} week_st, week_end;


Chapter 2.4 - Discuss how variables are used in a program | Part -1



DECLARATION OF VARIABLES

After designing suitable variables names, we must declare them to the compiler.
The declaration does two things:
  1. It tells the compiler what the variable name is.
  2. It specifies what type of data the variable will hold.
The declare of variables must be done before they are used in the program.

     C language tutorials for beginners

    Download Let us C eBook | by Yashwant Kanetkar

DECLARATION OF VARIABLES


Primary Type Declaration

A variable can be used to store a value of any data type. That is, the name has nothing to do with its type. The syntax  of declaring a variable is as follows:

data-type v1,v2,....vn
v1,v2,...vn are the names of variables. Variables are separated by commas. A declaration statement must end with a semicolon. For example, valid declarations are:

int count;            
int number, total;
double ratio;       



int and double are the keywords to represent integer type and real type data values respectively. Table 2.9 shows various data types and their keywords equivalents. #variables_in_c

Discuss how variables are used in a program | Part -1, What is a variable in computer programming, Computer Programming Variables, C variable with examples, attributes of a variable in programming.
Discuss how variables are used in a program | Part -1, What is a variable in computer programming, Computer Programming Variables, C variable with examples, attributes of a variable in programming.  


The program segment given in Fig 2.7 illustrates the declaration of variables. main() is the beginning of the program. The opening brace { single the execution of the program. Declaration of variables is usually done immediately after the opening brace of the program. The variables can also be declared outside (either before or after) the main function. The importance of the place of the declaration will be dealt with in detail later while discussing functions. #allaboutprogramming62



Note-: C99 permits declaration of variables at any point within  a function or block, prior to their use

Discuss how variables are used in a program | Part -1, What is a variable in computer programming, Computer Programming Variables, C variable with examples, attributes of a variable in programming.

When an adjective (qualifier) short, long, or unsigned is used without a basic data type specifier, C compilers treat the data types as an int. If we want to declare a character variable as unsigned, then we must do so using both the terms like unsigned char


Default values of Constants 

Integer constants, by default, represent int type data. We can override this default by specifying unsigned or long after the number (by appending U or L) as shown below:

Literal                             Type                                      Value

+111                                int                                           111
-222                                 int                                           -222
45678U                           unsigned int                           45678
-56789L                           long int                                  -56789
987654UL                       unsigned long int                   987654




Similarly, floating point constants, by default represent double type data. If we want the resulting data type to be float or long double, we must append the letter f or F to the number for float and letter l or L long for long double as shown below:


Literal                             Type                                      Value

0.                                     double                                     0.0
-222                                 double                                     0.0
45678U                           double                                     12.0
-56789L                          double                                     1.234
987654UL                       float                                       -1.2
1.23456789L                   long double                          1.23456789


           Top 10 Useful Basic Commands for Linux Users

           C Pattern Programming Example Tutorial 
                                                                                          



Chapter 2.3 - Identify the various C data types | Part - 2


Integer Types

Integers are whole numbers with a range of values supported by a particular machine. Generally, integers occupy one word of storage, and since the word sizes of machine vary (typically, 16 or 32 bits) the size of an integer that can be stored depends on the computer. If we use a 16-bit word length, the size of the integer is limited to the range -32768 to +32767 (that is, -215 to  + 215  -1). A signed integer uses one bit for a sign and 15 bits for the magnitude of the number, Similarly, a 32-bit word length can store an integer ranging from -2,147,483,648 to 2,147,483,647.


C Language Tutorials for Beginners                      



C data types


In order to provide some control over the range of numbers and storage space, C has three classes of integer storage, namely short int, int, and long int, in both signed and unsigned forms. ANSI C defines these types so that they can be organized from the smallest to the largest, as shown in the following Fig. 2.5. For example, short int represents fairly small integer values and requires half the amount of storage as a regular int number uses. Unlike signed integers, unsigned integers use all the bits for the magnitude of the number are always positive. Therefore, for a 16-bit machine, the range of unsigned integer numbers will be from 0 to 65,535. #c_datatype

We declare long and unsigned integers to increase the range of values. The use of qualifier signed on integers is optional because the default declaration assumes a signed number. Table 2.8 shows all the allowed combinations of basic types and qualifiers and their size and range on a 16-bit machine. #datatypes

                Download Turbo C++ Program Compiler


            Download Free Code::Block All Program Compiler


Identify the various C data types | Part - 2
Note: C99 allows long long integer types. See the Appendix "C99 Features"

 C data types





Floating Point Types

Floating point (or real) numbers are stored in 32 bits (on all 16 bit and 32-bit machines), with 6 digits of precision. Floating point numbers are defined in C by the keyword float. When the accuracy provided by a float number is not sufficient, the type double can be used to define the number. A double data type number uses 64 bits giving a precision of 14 digits. These are known as double precision numbers. 


Identify the various C data types | Part - 2

Remember that double type represents the same data type that float represents, but with greater precision. To extend the precision further, we may use long double which uses 80 bits. The relationship among floating types is illustrated in Fig 2.6.



Void Types

The void types have no values. This is usually used to specify the type of functions. The type of function is said to be void when it does not return any value to the calling function. It can also play the role of a generic type, meaning that it can represent any of the other standard types. 

        Top 10 Useful Commands for Linux Users

       C Programming Example Tutorial



Character Types


A single character can be defined as a character (char) type data. Characters are usually stored in 8bits (one byte) of internal storage. The qualifier signed or unsigned may be explicitly applied to char. While unsigned chars have values between 0 and 255, signed chars have valews from -128 to 127. #allaboutprogramming62

Chapter 2.3 - Identify the various C data types | Part -1



DATA TYPES

C language is rich in its data types. Storage representations and machine instructions to handle constants differ from machine to machine. The variety of data types available allow the programmer to select the types appropriate to the needs of the applications as well as the machine.
ANSI C supports three classes of data types:

  1. Primary (or fundamental) data types
  2. Derived data types
  3. User-defined data types
The primary data types and their extensions are discussed in this section. The user-defined data types are defined in the next section while the derived data types such as arrays, functions, structures, and pointers are discussed as and when they are encountered.
  


All C compilers support five fundamental data types, namely integer (int),  character (char), floating point (float), double-precision (double) and void. Many of them also offer extended data types such as long int and log variable. Various data types and the terminology used to describe them are given in Fig 2.4. The range of the basic four types is given in Table 2.7. We discuss briefly each one of them in this section #allaboutprogramming62.


Note:- C99 adds three more data types namely_Bool_Complex, &_Imaginary. See the Appendix "C99 Features"

Various C data types




Primary Data Types #allaboutprogramming62

Chapter 2.2 - Describe Constant and Variables



CONSTANTS

Constant in C refer to fixed values that do not change during the execution of a program. C supports serval types of constants as illustrated in Fig 2.2.

          C language tutorials for beginners

          Chapter 2.1 - C character set and keyword

Describe Constant and Variables

Integer Constant

An integer constant refers to a sequence of digits. There are three types of integers, namely, decimal integer, octal integer, and hexadecimal integer.
Decimal integers consist of a set of digits, 0 through 9, preceded by an optional - or + sign. Valid examples of decimal integers constant are:

123     -321     0     654321     +78

Integer Constant


Embedded spaces, commas, and non-digit characters are not permitted between digits. For example, 

15750     20,000     $1000

all illegal numbers.



An octal integer constant consist of any combination of the digit from the set 0 through 7, with a leading 0. Some examples of the octal integer are:

037     0     0435     0551

A sequence of digits preceded by 0x or 0X is considered as a hexadecimal integer. They may also include alphabet A through F or a through f. The letter A through F represent the numbers 10 through 15. Following are the examples of valid hex integers:

0X2     0x9F     0Xbcd     0x

We rarely use octal and hexadecimal numbers in programming.


The largest integer value that can be stored is machine-dependant. It is 32767 on 16-bit machines and 2,147,483,647 on 32-bit machines. It is also possible to store larger integer constant on these machines by appending qualifiers such as U, L and UL to the constants. Examples:

56789U             or 56789u            (unsigned integer)
98763234UL    or 98763234ul     (unsigned long integer)
987654L           or 9876543l         (long integer)

The concept of unsigned and long integers are discussed in detail in the Next Section.





WORKED-OUT PROBLEM 2.1

Representation of integer constant on a 16-bit computer.

        Download Turbo C++ Program Compiler               


The program in Fig 2.3 illustrates the uses of integer constant on a 16-bit machine. The output in Fig 2.3 shows that the integer values larger than 32767 are not property stored on a 16-bit machine. However, when they have qualified as long integer (by appending L), the values are correctly stored.

uses of integer constant on a 16-bit machine




Real Constant

Integer numbers are inadequate to represent quantities that vary continuously, such as distances, heights, temperature, prices, and so on. These quantities are represented by numbers containing fractional parts like 17.548. Such numbers are called real (or floating point) constant. Further examples of real constants are:

0.0083 -0.75  435.36 +247.0

These numbers are shown in decimal notation, having a whole number followed by a decimal point and the fractional part. It is possible to omit digits before the decimal point, or digits after the decimal points. That is,

215.     .95     -.71     +.5

are all valid numbers.

A real number may also be expressed in exponential (or scientific) notation. For example, the value 215.65 may be written as 2.1565e2 in exponential notation. e2 means multiply by 102. The general is:
mantissa e exponent 
The mantissa is either a real no expressed in decimal notation or an integer. An exponent is an integer number with an optional plus or minus sign. The letter e separating by the mantissa and the exponent can be written in either lowercase or uppercase. Since the exponent causes the decimal point to "float", this notation is said to represent a real number in floating point form. Examples of legal floating-point constants are:


0.65e4     12e-2     1.5e+5     3.18E3     -1.2E-1

Compile Program in Android Mobile             

Embedded white space is not allowed. 


Exponential notation is useful for representing numbers that are either very large or very small in magnitude. For example, 7500000000 may be written as 7.5E9 or 75E8. Similarly, -0.000000368 is equivalent to -3.68E-7.



The floating-point constant is normally represented as double-precision quantities. However, the suffixes f to F may be used to force single-precision and l or L to extend double precision further.
Some examples of the valid and invalid numeric constant are given in Table 2.4.

Describe Constant






Single Character Constant

A single character constant (or simply character constant) contains a single character enclosed within a pair of single quote marks. Example of a character constant is as follows:

'5'      'X'     ';'     '  '

Note that the character constant '5' is not the same as number 5. The last constant is blank space.
Character constants have integer values known as ASCII values. For example, the statement

printf("%d", 'a');

would print the number 97, the ASCII value of the letter a. Similarly, the statement

printf("c",'97');

would output the letter 'a'. ASCII values for all characters are given in Appendix II.
Since each character constant represents an integer value, it also possible to perform arithmetic operations on character constants. They are discussed in another post of our site.




String Constants

A string constant is a sequence of characters enclosed in double quotes. The characters may be letters, numbers, special characters, and blank space. Examples are: 
"Hello!" "1987" "WELL DONE" "?.....!" "5+3" "X"

                    Top 10 Useful Basic Commands for Linux user

Remember that a character constant (e.g., 'X') is not equivalent to the single character string constant (e.g., 'X'). Further, a single character string constant does not have an integer value while a character constant has an integer value. Character strings are often used in programs to build meaningful programs. Manipulation of characters strings is considered in detail in our other post. 




Backslash Character Constant

C supports some special backslash character constants that are used in output functions.  For example, the symbol '\n' stands for the newline character. A list of such backslash character constants is given in Table 2.5. Note that each one of them represents one character, although they consist of two characters. These characters combinations are known as an escape sequence





VARIABLES

A variable is a data name that may be used to store a data value. Unlike constants that remain unchanged during the execution of a program, a variable may take different values at different times during execution. In chapter 1, we used several variables. For instance, we used the variables amount in Worked Out Problem 3 to store the value of money at the end of each year (after adding the interest earned during that year).

A variable name can be chosen by the programmer in a meaningful way so as to reflect its function or nature in the program. Some examples of such names are:

Average
Height
Total
Counter_1
class_strenght

As mentioned earlier, variables names may consist of letters, digit, and the underscore(_) character, subject to the following conditions. 

  1. They must begin with a letter. Some systems permit underscore as the first character.
  2. ANSI standard recognizes a length of 31 characters.  However, length should not be normally more than eight characters, since only the first eight characters are treated as significant by many compilers. 
  3. Uppercase and lowercase are significant. That is, the variable Total is not the same as total or TOTAL.
  4. It should not be a keyword.
  5. White spaces are not allowed.
Some examples of valid variable names are:

John          Value         T-raise
   Delhi          x1             ph_value
  mark          sum1         distance

Invalid Examples Include:

123          (area)
        %        25th       

Chapter 2.2 - Describe Constant and Variables


If only the first eight characters are recognized by a compiler, then the two names

average_height
 average_weight

mean the same thing to the computer. Such names can be rewritten as

avg_height and avg_weight

or

ht_average and wt_average 

without changing their meanings. 


Comments System

blogger/disqus/facebook