Community Sites
Create your own community website and start earning today !
It's Free !
 
Communities Members BookmarksPolls Fresher Jobs Funny Pictures MCA Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter



Control Loop programs


Posted Date: 14 Jun 2008    Resource Type: Articles/Knowledge Sharing    Category: Computer & Technology

Posted By: Lenin       Member Level: Diamond
Rating:     Points: 1



Control Loop programs

This section contains example programs demonstrating the loop
construction.

Program using char data type and simple for loop:
#include /* library header */

main()
{
char ch;

for (ch = 'A' ; ch <= 'z' ; ch++) printf("%c\n" , ch);
}

This program demonstrates the while loop.
#include

main()
{
int lower , upper , step;
float fahr , celsius;

lower = 0 ;
upper = 300;
step = 20 ;

fahr = lower;

while ( fahr <= upper ) {
celsius = (5.0 / 9.0) * (fahr - 32.0);
printf("%4.0f %6.1f\n" , fahr , celsius);
fahr = fahr + step;
}
}

This program uses do-while and for loop constructions and standard library
mathematical functions.
#include
#include

main()
{
int i , j , k;
double a=10.0 , b=.0;

do {
printf("%f\n" , pow(a,b)); /* standard function */
b++;
} while (b<100);

i = 2;
for (j=2 ; j<100 ; j=j+2) {
i=i*j ;
printf("%d\n" , i);
}
}





Responses

Author: Tejwant Singh Randhawa    15 Jun 2008Member Level: Silver   Points : 2
nice programs collection in which he explained for, while & do...while loop. we can also create a infinite loop for while, for & do...while loop like this.

For Infinite loop
for(;;)
printf("hello");

this will print hello infinite times using for loop.

while Infinite loop
int a=1;
while(a<10)
{
printf("hello");
}
this will print hello infinite times using while loop.

do...while Infinite loop
int a=1
do
{
printf("hello");
}
while(a<10)

this will print hello infinite times using do...while loop


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Input and Output programs
Previous Resource: Conditional Execution programs
Return to Discussion Resource Index
Post New Resource
Category: Computer & Technology


Post resources and earn money!
 
Related Resources

Watch TV Channels



Contact Us    Editors    Privacy Policy    Terms Of Use   

SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.