Community Sites
Create your own community website and start earning today !
It's Free !
Forum
Resources
Mentors
Projects
Entrance Exams
Question Papers
Colleges
Courses
Universities
Schools
Make Money
Communities
Members
Bookmarks
Polls
Fresher Jobs
Funny Pictures
MCA Projects
New Member FAQ
My Profile
Sign In
Register
AdSense Revenue
Active Members
Today
bharath sudar
(10)
RajmiArun
(7)
NMU, jalgaon ...
(6)
Last 7 Days
sunil
(2113)
satish
(1712)
Saagar
(1633)
more...
Awards & Gifts
Online Exams
Aptitude Questions
General Aptitude Tests
Medical Entrance
Engineering Entrance
Bank Tests
TOEFL & IELTS Questions
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.
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 (a
printf("First number is less than second\n\n");
if (b
printf("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
Sign In
(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
Bluetooth
Useful Tips on Mobile Phone
Things to be done before Building a Custom Access Database
Informations related to computer hardwares
C Program to protect your folder
Watch TV Channels
Watch Asianet online
Kairali TV in Internet
Surya TV online
Amritha TV Channel
Contact Us
Editors
Privacy Policy
Terms Of Use
SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.