by Dinesh Thakur Category: Control Structures

In some situations we may have to change the order of execution of statements based on certain conditions , or repeat a group of statements until certain specified conditions are met. For these situation C provides decision making statements also know as control statements. C has following control statements:

 
by Dinesh Thakur Category: Control Structures

1. Factorial of a number.
2. Prime or not
3. Odd or even
4. Exit

Once a menu item is selected the appropriate action should be taken and once this action is finished, the menu should reappear. Unless the user selects the 'Exit' option the program should continue to work. 

 
by Dinesh Thakur Category: Control Structures

In this example, the initial and final values of loop variable i (of type int) are 1 and 10, respectively. The increment expression, i += 1, increases the value of i by 1. Thus, i assume values 1, 2, 3, 4 and 5.

 
by Dinesh Thakur Category: Control Structures

For loop: When it is desired to do initialization, condition check and increment/decrement in a single statement of an iterative loop, it is recommended to use 'for' loop.

 
by Dinesh Thakur Category: Control Structures

In this example, a for loop is set up with values of loop variable num from m to n. The if statement is executed for each value of num and if nums an odd number (num%2 equals 1), it is printed using the printf statement. The output of this code is given below for m= 20 and n=40.

 
by Dinesh Thakur Category: Control Structures

C has GOTO statement but one must ensure not to use too much of goto statement in their program because its functionality is limited and it is only recommended as a last resort if structured solutions are much more complicated. First let us see what the goto statement does, its syntax and functionality. The goto is a unconditional branching statement used to transfer control of the program from one statement to another.

 
by Dinesh Thakur Category: Control Structures

C has looping , in which a sequence of statements are executed until some conditions for termination of the loop are satisfied.

 
by Dinesh Thakur Category: Control Structures

The program segment given below accepts numbers from the keyboard until we enter a zero or a negative number and calculates their sum excluding the last number.

 
by Dinesh Thakur Category: Control Structures

This program segment given below uses a straight-forward approach to count the number of odd and even digits in a given integer number(num).

 

Page 1 of 7

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content





Popular Article