Computer Science Studies (BIT)

This fourm is created by Sir Muhammad Tahir Farooq. The purpose of creating this fourm to share information the students.
 
HomeHome  RegisterRegister  Log inLog in  
Aslam-O-Alikum!
Search
 
 

Display results as :
 
Rechercher Advanced Search
Calender
Latest topics
» Chapter #1 Complete MCQ's (PART-1)
Tue Feb 24, 2015 6:00 am by Shaheer

» Windows Operating System (COMPLETE)
Mon Jan 26, 2015 10:17 am by shaista

» Computer Architecture (COMPLETE)
Sun Jan 25, 2015 5:52 am by shaista

» A virus that create more folders in your computer
Tue Jan 06, 2015 3:49 am by tahir48

» Browsers Comparision
Tue Jan 06, 2015 3:39 am by tahir48

» WEb to PDF convert
Sun Jan 04, 2015 7:34 am by shaista

» 7th Class Computer paper 1st 2 Chapters
Mon Dec 08, 2014 6:21 pm by shaista

» 8th Class Computer Paper 1st 2 chapters
Mon Dec 08, 2014 6:16 pm by shaista

» Chapter # 1 9th Class
Mon Dec 08, 2014 2:52 am by shaista

Poll
Top posters
Admin
 
shaista
 
tahir48
 
computerstudent18
 
computerstudent29
 
thompson john
 
Shaheer
 
Statistics
We have 30 registered users
The newest registered user is benish

Our users have posted a total of 214 messages in 210 subjects
Flag Counter

Share | 
 

 LOOP Complete Topic

Go down 
AuthorMessage
Admin
Admin
Admin
avatar

Posts : 114
Join date : 2012-10-29
Location : Lahore Pakistan

PostSubject: LOOP Complete Topic   Mon Sep 16, 2013 7:05 pm

Q: what is loop? Ans: A statement or set of statements that is executed repeatedly is known as loop, or iteration. There are three types of loops available in C language.
1.       For Loop
i)        Counter loop
2.       Conditional Loop
ii)       While loop
iii)     do-while loop
Q: What is “while” loop? Ans: while loop is the simplest loop of C language. This loop executes one or more statements while the given condition remains true. Syntax:  While(condition)              statement;
The syntax of compound statement as :
While (condition)
{
Statement 1;
Statement 2;
:
Statement N;                                                      
}
ü  write a program that displays “Pakistan” for five times using while loop.(int n; n=1; while(n<=5); n++; and \n).
ü  write a program that displays counting from 1 to 10. (int n; while(condition) n++Wink
ü  write a program that displays first five numbers and their sum using while loop.(int c,sum; sum=0 while(condition) sum=sum+c;)
ü  write a program that displays first 5 numbers with their squares using while loop.(n=1;, while(n<=5), printf(“%d %d\n”,n,n*n);, n++Wink
ü  write a program that inputs a number from the user and displays the factorial of that number using while loop.
                                                                                                                                                                                     


 
ü  What is do-while loop? The do-while is an iterative control in  c language. This loop execute one or more statements while the given condition is true. In this loop, the condition comes after the body of loop. The loop is important in a situation where a statement must be executed at least once.
Syntax:  do
                {
                                Statement 1;
                                Statement 2;
                                :
                                :
                                Statement N;
                }
                While (condition);
ü  What is difference b/w while and do-while loops?
While loop:Y in while loop, conditions comes before the body of the loop. Y if condition is false in the beginning, while loop is never executed. Y the semicolon is not used after the condition.
do-while loop: Y in do-while loop, condition comes after the body of the loop. Y do-while is executed at least once even if conditions is false in the beginning. Y semicolon is used after the condition.
Program: write a program that displays first ten odd numbers using do-while loop.
                                                                                                                                                                                                                                                                                                                                                                                                                              
 
                                                                                                                                                                                   


 
Back to top Go down
http://computerstudies.forumotion.com
 
LOOP Complete Topic
Back to top 
Page 1 of 1
 Similar topics
-
» Complete meal cooking
» 95 DCM Impala Complete Part Out
» Trailer Park Boys Complete Series DVDRip
» [Durian Trail] Rifle Range Road - Durian Loop Trail - 10 Mar 2013 0900hrs
» Infernity Guide+infinite loop

Permissions in this forum:You cannot reply to topics in this forum
Computer Science Studies (BIT) :: Classes :: Second Year Standard-
Jump to: