Programming

FORUM Dedicated to Programming
 
HomePortalCalendarFAQSearchMemberlistUsergroupsRegisterLog in

Share | 
 

 Loop practice questions in C and C++

View previous topic View next topic Go down 
AuthorMessage
Admin
Administrator
Administrator


Number of posts : 22
Age : 26
Registration date : 2008-11-12

PostSubject: Loop practice questions in C and C++   19/11/08, 07:04 pm

Practice Problem 1

Print the pattern like shown below with loops , where the number of stars in first row rectangle is input by user

Example if no of stars are 11 in first rectangle

* - ***********
*** - *********
***** - *******
******* - *****
********* - ***
*********** - *


Practice Problem 2

Print the pattern like shown below with loops , where the X(variable) is input by user

Example if X is 6

*** ******
****** ***
*** ******
****** ***
*** ******
****** ***

Example if X is 8

**** *******
******* ****
**** *******
******* ****
**** *******
******* ****
**** *******
******* ****
Back to top Go down
View user profile http://programming.6forum.info
nouman
Level 0
Level 0


Number of posts : 1
Registration date : 2008-11-15

PostSubject: Re: Loop practice questions in C and C++   25/11/08, 09:59 pm

hey ppl sort me out m nt good at loops ....meri watt lag rai hai in main ..can any body help me for this ..i will b very very greatfull to that person ...thnx
i mean how to implement nested loops in a right way .....
Back to top Go down
View user profile
ammar26
Administrator
Administrator


Number of posts : 18
Age : 26
Registration date : 2008-11-12

PostSubject: Practice .....   25/11/08, 10:05 pm

You just have to practice more and more in order to get command

Remember some points while doing nested loops

1 - Make sure you use different variables for controlling the counter of both loops ( if you are working with counter control loops)

2 - Always reset the counter of inner loop before its start in outer loop

3 - Always make sure to use delimiters inside loops and right align the inner loop so that you can understand easily

4 - Do not make such conditions in which both loops can collide
Back to top Go down
View user profile http://www.softxtreme.com
Admin
Administrator
Administrator


Number of posts : 22
Age : 26
Registration date : 2008-11-12

PostSubject: Get familer with syntax and sequence ........   26/11/08, 04:41 pm

Like While Loop Syntax

The while loop executes as long as the conditional expression remains true (therefore it is required that the code within the loop manipulates the conditional expression in such a way as to eventually result in the stopping condition so that the loop does not execute forever...)

while (condition)
{
statement 1;
statement 2;
.
.
statement n;
}

Consider the following example

int x;
while (x < 10)
{
DoSomething; // any statement
x = SomeCodeResult;
}

The loop code manipulates the variable x and should eventually return a result that makes x greater than or equal to ten so that the loop terminates at some point.
Back to top Go down
View user profile http://programming.6forum.info
Admin
Administrator
Administrator


Number of posts : 22
Age : 26
Registration date : 2008-11-12

PostSubject: I'll make some posts for nested loops   26/11/08, 04:44 pm

I'll make some posts for nested loops practice

nouman I'll create a specific topic in forums and will do some posts related to nested loops instructions
So that you will be more familiar with nested loops structure
Back to top Go down
View user profile http://programming.6forum.info
Hafiz Talha
Level 0
Level 0


Number of posts : 2
Registration date : 2008-11-15

PostSubject: must do for begginers   05/12/08, 03:33 pm

these are very gud and intrsting questions and these are must do for the begginers. a very gud loop practice.
i'll try to solve n post the solutions of these problems
Back to top Go down
View user profile
precious.logic
Level 0
Level 0


Number of posts : 2
Age : 28
Registration date : 2008-11-20

PostSubject: Here is the solution of question   16/12/08, 03:35 pm

Problem Num 1:

#include<iostream.h>
#include<conio.h>

main (){

int a=1,b=0;
clrscr();
cout<<"Enter The num of to print the star=";
cin>>b;
while(b>0){

int c=0,d=0;
while(c<a){
cout<<"*";
c++;
}
cout<<"-";

while(d<b){

cout<<"*";
d++;
}
cout<<"\n" ;

a=a+2;
b=b-2;

}

getch ();
return 0;

}



Problem Num 2:

# include<iostream.h>
# include<conio.h>
main (){
int a=0,b=0,e=0;
clrscr ();
cout<<"Enter a num to print the stars";
cin>>b;
a=b/2;
e=b;
while(b>0){
int c=0,d=0;
if(b%2==1){
while(c<a){
cout<<"*";
c++;
}
cout<<" " ;

while(d<e){

cout<<"*";
d++;
}
}
else {


while(d<e){

cout<<"*";
d++;
}
cout<<" " ;

while(c<a){
cout<<"*";
c++;
}
}

cout<<"\n";
b--;

}

getch();
return 0;
}

Back to top Go down
View user profile
ammar26
Administrator
Administrator


Number of posts : 18
Age : 26
Registration date : 2008-11-12

PostSubject: Thanks Faizan ...   17/12/08, 05:19 am

Thanks precious.logic for solution of practice questions in C
Back to top Go down
View user profile http://www.softxtreme.com
brajraj
Level 0
Level 0


Number of posts : 1
Age : 42
Registration date : 2012-04-23

PostSubject: Re: Loop practice questions in C and C++   23/04/12, 06:47 am

Practice Problem 1

[#include
#include
main()
{
int i=1,j=1,m=2;
for(i=1;i<=6;i++)
{
for(j=1;j<=12;j++)
{
if(m==j)
{
cout<<"-";

}
cout<<"*";

}

m=m+2;
cout<<"\n";
}
getch();

}
]
Back to top Go down
View user profile
Sponsored content




PostSubject: Re: Loop practice questions in C and C++   

Back to top Go down
 
Loop practice questions in C and C++
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Answer these questions with song titles
» How Click on Dynamic Objects at Dynamic Positions in Selenium using for loop
» EEG Questions
» Few questions about switching to Selenium
» Chiari surgery on Private Practice episode last night. Cheryl did you see this episode?

Permissions in this forum:You cannot reply to topics in this forum
Programming :: C & C++ Programming :: C & C++ Discussions & Solutions-
Jump to: