by Dinesh Thakur Category: Control Structures

The outer for loop is set up to process each number in the given range. Each number is tested within this loop using the simplified code. The execution of the break statement causes inner for loop to terminate as it is the nearest loop enclosing the break statement. If the inner for loop is completely executed, i. e., if condition d == num is true, num is printed as a prime number.

 
by Dinesh Thakur Category: Control Structures

The if statement within the body of the for loop is used to print a comma after each value of the loop variable except the last one.

Consider the code given below to print a comma-separated list of numbers from 1 to 10:

 
by Dinesh Thakur Category: Control Structures

Three positive integer numbers a, band c, such that a<b<c form a Pythagorean triplet if c2= a2 +b2 , i. e,, a, b and c form the sides of a right-angled triangle. To select the values of a and b such that a < b and a, b < max, we can use nested for loops as shown below:

 
by Dinesh Thakur Category: Control Structures

switch statement is generally best to use when you have more than two conditional expressions based on

a single variable of numeric type. For instance, rather than the code

 
by Dinesh Thakur Category: Control Structures

A program to determine the sum of digits of a given non-negative integer number using a while loop is presented in Program. The program segment given below does the same thing using a do...while loop. 

 
by Dinesh Thakur Category: Control Structures

Let us use variables m and n to represent two integer numbers and variable r to represent the remainder of their division, i. e., r = m % n. Euclid's algorithm to determine the GCD of two numbers m and n is given below and its action is illustrated form= 50 and n = 35.

 
by Dinesh Thakur Category: Control Structures

No, but it is not a bad idea to put default statements in switch statements for error- or logic-checking

purposes. For instance, the following switch statement is perfectly normal:

 
by Dinesh Thakur Category: Control Structures

Switch statement is a powerful statement used to handle many alternatives and provides good presentation for C program. But there are some limitations with switch statement which are given below:

 
by Dinesh Thakur Category: Control Structures

As the name indicates, the prime factors of a given number are its factors that are also prime numbers, e.g., prime factors of 30 are 2, 3 and 5 but not 1, 6, 10, 15 and 30. One or more prime factors of a given number may repeat, e. g., prime factors of 120 are 2, 2, 2, 3 and 5.

 

Page 2 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