Programming Tutorials Collection

How to write a program in C using for Loop?

Google+ Pinterest LinkedIn Tumblr

For loop is the most popular looping structure in C programming language. It does required number of repetitions for the execution of block of codes. The For Loop allows us to specify three things about a loop in a single line, which are initialise counter, test counter and increment counter. Initialise counter sets a loop counter to an initial value, test counter test the loop counter to determine whether it’s value has reached the number of repetitions desired and increment counter increase the value of loop counter each time the program segment within the loop has been executed. Here I have illustrated How to write a program in C using for Loop.

The general form of for statement is as follows.

for(initialise counter; test counter; increment counter)
block of codes

The diagram for the for loop is as follows.
write a program in C using for Loop

For example following is the program code in C to calculate simple interest. 

/*calculation of simple interest for 3 sets of
p,n and r */
#include <stdio.h>
 int main()
int p,n,count;
float r,si;
for(count=1; count<=3; count=count+1)
 printf(“Enter values of p,n and r”);
 scanf(“%d %d%f”,
printf(simple interest=%fn”,si);
 return 0;

Shuseel Baral is a web programmer and the founder of InfoTechSite has over 8 years of experience in software development, internet, SEO, blogging and marketing digital products and services is passionate about exceeding your expectations.

Write A Comment