Programming
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Programming

FORUM Dedicated to Programming
 
HomePortalLatest imagesSearchRegisterLog in

 

 Loop practice questions in C and C++

Go down 
+2
nouman
Admin
6 posters
AuthorMessage
Admin
Administrator
Administrator



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

Loop practice questions in C and C++ Empty
PostSubject: Loop practice questions in C and C++   Loop practice questions in C and C++ I_icon_minitime19/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
http://programming.forumakers.com
nouman
Level 0
Level 0



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

Loop practice questions in C and C++ Empty
PostSubject: Re: Loop practice questions in C and C++   Loop practice questions in C and C++ I_icon_minitime25/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
ammar26
Administrator
Administrator



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

Loop practice questions in C and C++ Empty
PostSubject: Practice .....   Loop practice questions in C and C++ I_icon_minitime25/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
http://www.softxtreme.com
Admin
Administrator
Administrator



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

Loop practice questions in C and C++ Empty
PostSubject: Get familer with syntax and sequence ........   Loop practice questions in C and C++ I_icon_minitime26/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
http://programming.forumakers.com
Admin
Administrator
Administrator



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

Loop practice questions in C and C++ Empty
PostSubject: I'll make some posts for nested loops   Loop practice questions in C and C++ I_icon_minitime26/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
http://programming.forumakers.com
Hafiz Talha
Level 0
Level 0



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

Loop practice questions in C and C++ Empty
PostSubject: must do for begginers   Loop practice questions in C and C++ I_icon_minitime05/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
precious.logic
Level 0
Level 0



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

Loop practice questions in C and C++ Empty
PostSubject: Here is the solution of question   Loop practice questions in C and C++ I_icon_minitime16/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
ammar26
Administrator
Administrator



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

Loop practice questions in C and C++ Empty
PostSubject: Thanks Faizan ...   Loop practice questions in C and C++ I_icon_minitime17/12/08, 05:19 am

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



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

Loop practice questions in C and C++ Empty
PostSubject: Re: Loop practice questions in C and C++   Loop practice questions in C and C++ I_icon_minitime23/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
Sponsored content





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

Back to top Go down
 
Loop practice questions in C and C++
Back to top 
Page 1 of 1
 Similar topics
-
» help in loop

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