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



Structure and Nesting programs


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

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



Structure and Nesting programs

This section contains example programs demonstrating nested block
structures.

This program uses nested for loop construction.
#include

main()
{
int i , j;

for (i=2 ; i<1000 ; i++) {
for (j=2 ; j<= i/2 ; j++)
if (!(i%j)) break;
if (j>i/2) printf("%d is a prime\n" , i);
}
}

This example program uses a do-while and nested if else construction.
#include

main()
{
int a , b;

do {

printf("Enter first number: ");
scanf("%d" , &a);
printf("Enter second number: ");
scanf("%d" , &b);

if (aprintf("First number is less than second\n\n");
if (bprintf("Second number is less than first\n\n");
} while (a < 999);
}

This program uses nested for loop and if else construction.
#include
#include

main()
{
int answer, count, chances, right;
for (count=1; count<11; count++) {
printf("What is %d + %d?", count, count);
scanf("%d", &answer);
if (answer == count+count) printf("Right!\n");
else {
printf("Sorry, you're wrong \n");
printf("Try again\n");
right = 0;
/* nested for *?
for (chances=0; chances<3 && ! right; chances++){
printf("\nWhat is %d + %d?",count, count);
scanf("%d", &answer);
if (answer == count+count){
printf("Right!\n");
right=1;
}
}
/* if answer still wrong, tell user */
if (!right)
printf("the answer is %d.\n", count+count);
} /* end of else part */
} /* end of outter for loop */
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

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: Conditional Execution programs
Previous Resource: Functions and Prototype 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.