Table of Contents
generally in programming languages, looping statements used to perform of a condition of the block of code.
C program has 3 looping statement
here we can clearly understand for loop in C language
Syntax
for ( initializationstatement; condition; increment/dicrement ) {
statement(s);
}
first the initialization statements are executed only once
Then the test expression is evaluated when the test expression becomes false. The control comes out from the loop and for loop is terminated.
However, when the test expression evaluated to true, statements inside the body of for loop are executed.
finally, the updating statement(increment/decrement) is updated
then again the test expression is evaluated
This process happening on until the test expression becomes false.
For loop starts from initialization statements.
The test expression is evaluated. if the test expression is false (boolean check), the flow of control skips from the loop. for loop is terminated, but if the test expression is true codes inside in the body of for loop is executed and then update statement is updated.
program 1
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;
/* for loop execution*/
for(a=10; a<20; a=a+1){
printf(“value of a is %dn”,a);
}
return 0;
}
Find factorial of the number
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,i;
long factorial=1;
printf(“Enter an integer number..”);
scanf(“%d”,&n);
// show error if user enter a negetive integer
if(n<=0){
printf(“Error you must enter positive numbern”);
}
else{
for(i=1; i<=n; ++i) // single for loop
{
factorial*=i;
}
printf(“factorial of %d=%11u”,n,factorial);
}
return 0;
}
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.