How To Guides
Control Instructions in C Language
Control instructions in C language enable the user to specify the order in which different instructions in a program has to be executed by the computer. We can say that control instructions determine the ‘flow of control’ in a program. Control Instructions in C language are of four types.
- Sequence Control Instructions
- Selection or Decision Control Instruction
- Repetition or Loop Control Instructions
- Case Control Instruction
Sequence Control Instructions
This type of instruction that ensures that the instructions are executed in the same order in which they appear in the program.
Selection or Decision Control Instruction
This type of instructions lets the computer to take a decision to which the instruction is to be executed next.
Repetition or Loop Control Instruction
Loop Control Instruction helps computer to execute group of statements repeatedly (on loop).
Case Control Instruction
Like Decision Control instruction, Case Control instruction allows the PC to take a decision to which the excution needs to be executed next.
In C language a decision control instruction can be implemented
- the if statement
- The if-else statement
- The conditional operators
The if Statement
Like most of the languages, C also uses the keyword if to implement decision control instruction. The general look of this statement is as under.
if ( this condition is true )
execute this statement ;
This statement tells the compiler that what follows is a decision control instruction. The condition which follows the if statement is always enclosed in parentheses. If the statement is true then it is executed and if the statement is not true then it will be executed.
The if-else Statement
This type of statement will execute if a specified condition is true. But if the condition is false another block of code will be executed. For that else statement is used.
Types of Instructions on C language
In C language there are basically three types of instructions which are as follows
- Type Declaration Instruction
- Arthimetic Instruction
- Control Instruction
Type Declaration Instruction:
This instruction is used to declare the type of variables used in a C program. Any of the variable is used in the program needs to be declared before using it in any statement. The type declaration statement is started at the beginning of main() function.
There are some fine variations of the type declaration instruction which are as follows
While declaring the type of variable we can initialize it as shown below.
int i = 10, j = 25 ;
float a = 1.5, b = 1.99 + 2.4 * 1.44 ;
The order if variable definition is sometimes very important and sometimes not. e.g.
int i = 10, j = 25 ;
is similar to
int j = 25, j = 10 ;
However,
float a = 1.5, b = a + 3.1 ;
is alright, but
float b = a + 3.1, a = 1.5 ;
is not alright. The reasin behind this is that we are trying to use a even before defining it.
Arithmetic Instruction:
This type of instruction is used to perform arithmetic operations between constants and variables. An arithmetic instruction consists of variable name of the left side of = and variable names and constants on the right side of =. The variables as well as constants which are appearing on the right side of = are connected by arithmetic operators like +,-,* and /.
For example
int ad ;
float kot, deta, alpha, beta, gamma ;
ad = 3600 ;
kot = 0.0076 ;
deta = alpha * beta / gamma + 4.2 * 3 / 7 ;
Here
- *, /, -, + are the arithmetic operators.
- = is the assignment operator.
- 3, 7 and 3600 are integer constants.
- 4.2 and 0.0076 are real constants.
- ad is an integer variable.
- kot, deta, alpha, beta, gamma are real variables.
Control Instruction:
Control instruction is used to control the sequence of execution of various statements in the C program.
Creating a Program in C Language
There are some rules for writing a program in C language and before writing the program you should have the knowledge of all the rules. Here are the rules you need to follow.
- Each of the instruction in the C program is written in the separate statement. So we can say that a C program would be composed of a series of statements.
- All the statement in the program should appear in the same order in which we want them to be executed unless the logic of the problem requires a jump or transfer of the control to a statement which is out of sequence.
- You can insert blank spaces between two words to enhance the readability of the statement. However you can not add blank spaces within a variable, constant or keyword.
- All of the statements needs to be entered in small case letters.
- C language has got no specific rules for the position at which the statement needs to be written, therefore it is known as a free-form language.
- Each C statement needs to be ended with a ; so ; acts as a statement eliminator.
Here is an example of C language program
/* Calculation of simple interest */
/* Author gekay Date: 5/10/2020 */
main( )
{
int p, n ;
float r, si ;
p = 1000 ;
n = 3 ;
r = 8.5 ;
/* formula for simple interest */
si = p * n * r / 100 ;
printf ( “%f” , si ) ;
}
Here are few tips about the above mentioned program
- The comments about the program needs to be enclosed within /* */. like the first two statements in our program are comments.
- Comments are not necessary but it is advisable to add comments in your program indicating the purpose of the program.
- You can add any number of comments in the program and at any place like you can add comment before the statement, after the statement or within the statement.
- In /* .. */ normal rules of the language do not apply therefore you can type the text in any case or combination.
- A comment can be split over more than one line like
/* This is
a test
program */
Constants and Variables in C Language
Constants in C language
A constant is any entity that does not change it’s value. Constants have two types which are
- Primary Constants (Integer Constant, Real Constant, Character Constant)
- Secondary Constants (Array, Pointer, Structure, Union, Enum etc)
Integer Constants Construction Rules
- An integar contant needs to have at least one digit.
- It must not have a decimal point.
- The Integer can be either positive or negative.
- If there is no sign before an integer then it is a positive integer.
- You can add commas or blanks within an integer constant.
- The integer constants range is -32768 to 32768.
Real Constant Construction Rules:
Real Constants are also known as Floating Point constants. These constants can be written in two forms which are Fractional form as well as Exponential form.
Here are the rules that you need to observe while constructung real constants expressed in the fraction form.
- Real constant must have a decimal point.
- It must have minimum of one digit.
- This constant can be positive or negative.
- The default sign of Real integer is positive.
- You can not add commas or blanks with a real constant.
Character Constant construction Rules:
- A Character constant is a single alphabet, digit ot a special symbol that has been enclosed into a single inverted commas. Both of the inverted commas should point to the left.
- Character constant’s maximum length can be one character.
C – Variables
A variable is an entity that may change during thr execution of the program. Variables names are the names given to the locations in the memory. The locations can contain integer, real or the character constants. The rules for constructing constants vary with the type of constant but the rules for constructing the variables in same.
Rules for Constructing Variable Names:
- A variable name is any of the combination of 1 to 31 alphabets, numbers or underscores.
- The character in the variable name must be an alphabet or underscore.
- You can not add any commaor blank within the variable name.
- You can not use any special symbol in a variable name other than an underscore.
Basics of C language
History
C is a programming language that has been developed by AT & T’s Bell Laboratories, USA in 1972. Dennis Ritchie was the man behind the designing and writing this language. C language gradually replaces it’s competitors like ALGOL, PL/I etc. C was never advertised but still programmers were preferring this language and it’s inventor was amazed at it. The reason behind the popularoty of C languages wwas its simplcity, ease of use and realiability. You may wonder that there are many languages that have surpassed C language like C++ and Java etc. but the fact is that for complete understanding of C++ and Java languages C language is a must.
Learning C Language
If you need to communicate with computer you need a language that computer understnads which means English is not the language of choice here. The first step of learning C language is to learn the alphabets, numbers and special symbols which are used in C. After this you need to know how to use constants, variables and keywords. All of these with a group of instructions form a program.
The C Character Set:
A character in C languages is any alphabet, number or special symbol used for representing information. The valid alphabets, numbers and special symbols are as follows
Alphabets | A, B, C, D, E, …….., X, Y, Z. a,b,c,d,e,………………..x,y,z. |
Digits | 0,1,2,3,4,5,6,7,8,9 |
Special Symbols | ~ ‘ ! @ # % ^ & * ( ) _ – + = | \ { } [ ] : ; ” ‘ < > , . ? / |
Constants, Variables and Keywords
The alphabets, numbers as well as special symbols mentioned above when combined in a proper way will form constants, variables and keywords.
Constant:
A constant is an entity that does not change it’s value. There are two types of constants i.e. Primary Constants and Secondary Constants.
Variable:
A variable is an entity that changes it’s value.
Keywords:
Keywords are actually the words whose meaning has been explained to the C compiler.
Working with Functions in MS Excel
Functions are the built-in formulas in MS Excel which will let you to perform common calculations on data easily. Functions can be entered in a worksheet using keyboard, AutoSum drop-down menu or Insert Function. You can also learn about Inserting and Positioning Picture in MS Word.
Using Keyboard for Finding the Average:
With the following steps you can calculate the average value of any data by using AVERAGE function.
- 1st of all select the cell where the result will appear e.g. E5.
- Now type =av to display the Formula AutoComplete list.
- Point to AVERAGE function and then double click.
- Now you need to select the range B5:D5 to insert it as argument to the AVERAGE function.
- Now you need to press the Enter key.
Using Insert Command to Find the Highest Value:
For finding the highest value you need to follow these simple steps.
- 1st of all you need to select cell B11 where the answer will appear.
- Now click Insert Function command and you will notice that Insert Function dialog box will be displayed.
- Now select MAX in the function list and then click OK.
- Now type B5:B8 in the Number 1 text box of Function Arguments dialog box and then click OK.
Using AutoSum Drop-down Menu to Find the Lowest Value:
With the following simple steps you can find the lowest value in the range B5:B8 by using AutoSum drop-down menu.
- 1st of all you need to select the cell B12 where the answer will appear.
- Now click on the Formulas tab.
- In the next step you are required to open the AutoSum drop-down menu in the Function Library group and then select Min.
- Now you need to type the range B5:B8 and then press Enter.
Inserting and Positioning Picture in MS Word
MS Word is a handy application for creating text documents and it is the most widely used text editing application all across the world. With MS Word text documents can be created very easily. In MS Word you can easily insert a picture in your documents so that your documents can be enhanced greatly. You can also learn about Saving and Sharing Documents in MS Word 2013. For Inserting a picture in a document you need to follow these simple steps.
- 1st of all you need to place the cursor where to insert the picture.
- Now in the next step you are required to click on the Insert tab.
- After this click on the Picture command present in the Illustrations group. You will notice that the Insert Picture dialog box will appear.
- Now you need to browse and select the picture file to insert and then click Insert button.
Positioning the Picture within a Page:
With the following simple steps you will be able to position a picture on page.
- 1st of all click the picture that is to be positioned. You will notice that Format tab will appear on the screen.
- Now in the next step you need to click on Position the command on the Arrange group.
- Now you are required to select a position from the menu. e.g. top right corner or top left corner etc.
- Once the position is defined the picture will be positioned in your page.
With these simple step you will be able to insert and position the pictures easily.