Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 12-12-2008, 05:11 PM   #1 (permalink)
learnhardy
 
Join Date: Oct 2008
Posts: 104
Default pattern problem in c


I want only program logic for this pattern ....."a c letter pyramid in which first row have one c letter ,second row have three ,third row have 5 and so on.......
please don't assign me a several printf() and tab and newline character.....as an option......!!!!
It be made with two for loops that is in one loop tab is decreasing and letter "c" is increasing in the second loops.??......or any other best option guys.....!!!!!
__________________
Newbie......
celebrate an ancient art .....
http://ambika.99k.org

Last edited by ambika; 12-12-2008 at 05:38 PM. Reason: pattern not appeared correctly
ambika is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 12-12-2008, 05:56 PM   #2 (permalink)
Legen-wait for it-dary!
 
dheeraj_kumar's Avatar
 
Join Date: Dec 2004
Location: Chennai
Posts: 2,471
Default Re: pattern problem in c

This is fairly simple, although newbies have a tough time with this. You can do it as long as you understand how the no. of letters are generated.

for row 1, 1 letter
for row 2, 3 letters
for row 3, 5 letters
for row 4, 7 letters

you can identify a simple pattern. For row number 'n', it will contain '(2*n) - 1' letters.
Code:
for( i = 1; i <= n; i++ )
{
    printf( "\n" );
    for( j = 1; j <= ( (2*n) - 1 ); j++)
        printf( "c" );
}
__________________
If the Start Windows Restart when Windows starts check box is checked Windows Restart will start automatically every time Windows is started. - Actual excerpt from a windows program help file
dheeraj_kumar is offline  
Old 13-12-2008, 07:21 PM   #3 (permalink)
learnhardy
 
Join Date: Oct 2008
Posts: 104
Default Re: pattern problem in c

This is not the case .........this triangle is equilateral triangle.....not a right angle triangle ......!!!!

I am new to this forum can anyone assign me ....how can i use drawing tools in this forum......my pattern not appearing right.


__________________
Newbie......
celebrate an ancient art .....
http://ambika.99k.org

Last edited by ambika; 13-12-2008 at 07:30 PM.
ambika is offline  
Old 13-12-2008, 07:54 PM   #4 (permalink)
Always confused
 
vamsi360's Avatar
 
Join Date: May 2008
Location: Mandriva Control Center
Posts: 349
Default Re: pattern problem in c

then use nested for loops one for dividing the screen into two and starting from the middle and the other to print the letter

here it goes......very difficult to type here

main()
{
int i,j,n;
printf("Enter the number of lines");
scanf("%d",&n);
for(i=1,i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
print("%4c",c);
}
printf("\n");
}
printf("\n");
}
__________________
Vamsi Subhash
visit my blog at www.vamsisubhash.co.cc and taste a bit of IT!

Last edited by vamsi360; 13-12-2008 at 08:02 PM. Reason: Automerged Doublepost
vamsi360 is offline  
Old 13-12-2008, 08:05 PM   #5 (permalink)
learnhardy
 
Join Date: Oct 2008
Posts: 104
Default Re: pattern problem in c

Hey ,vamsi360.... u r rignt .....i am just wanted this answer from someone ...please tell me how can this be done.
__________________
Newbie......
celebrate an ancient art .....
http://ambika.99k.org
ambika is offline  
Old 13-12-2008, 08:06 PM   #6 (permalink)
Always confused
 
vamsi360's Avatar
 
Join Date: May 2008
Location: Mandriva Control Center
Posts: 349
Default Re: pattern problem in c

starting from the first.....in the second printf the gap between the quotes is 4 spaces and hence %4d in the 3rd printf.In the thread the spaces are gone

first as I said divide the screen to half so that you can start from the middle.Hence characters get displayed on both left and right.Rest you can easily understand if you get the main logic
__________________
Vamsi Subhash
visit my blog at www.vamsisubhash.co.cc and taste a bit of IT!

Last edited by vamsi360; 13-12-2008 at 08:08 PM. Reason: Automerged Doublepost
vamsi360 is offline  
Old 13-12-2008, 08:19 PM   #7 (permalink)
learnhardy
 
Join Date: Oct 2008
Posts: 104
Default Re: pattern problem in c

can anyone provide me a online c compiler....
__________________
Newbie......
celebrate an ancient art .....
http://ambika.99k.org
ambika is offline  
Old 13-12-2008, 08:24 PM   #8 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: pattern problem in c

Why don't you figure out a way to print spaces if this following one is what you want:

Code:
   *
  ***
 *****
  ***
   *
In C:
PHP Code:
#include <stdio.h>

int main(int argcchar **argv) {
    
int n 5ij;
    
printf("Enter no. of rows: ");
    
scanf("%d", &n);
    for(
i=1i<ni++) {
        for(
j=0j<n-i+1j++) { printf(" "); }
        for(
j=0j<(2*i)-1j++) { printf("c"); }
    
printf("\n");
    }
    for(
i=ni>0i--) {
        for(
j=n-i+1j>0j--) { printf(" "); }
        for(
j=(2*i)-1j>0j--) { printf("c"); }
    
printf("\n");
    }
    return 
0;

There are no online C "compilers", but a useful, limited interpreter might be found here.

Output of vamsi360's program:
Code:
       c
      c   c
     c   c   c
    c   c   c   c
   c   c   c   c   c
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 13-12-2008, 08:31 PM   #9 (permalink)
Always confused
 
vamsi360's Avatar
 
Join Date: May 2008
Location: Mandriva Control Center
Posts: 349
Default Re: pattern problem in c

hey qwerty i have said to adjust the spaces in quotes as I typed here and not pasted it from editor.Look at it with 4 spaces in quotes and %4c you will get the desired output
__________________
Vamsi Subhash
visit my blog at www.vamsisubhash.co.cc and taste a bit of IT!
vamsi360 is offline  
Old 13-12-2008, 08:35 PM   #10 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: pattern problem in c

I posted the output only cause I guessed the OP was looking to run it.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 13-12-2008, 08:42 PM   #11 (permalink)
Always confused
 
vamsi360's Avatar
 
Join Date: May 2008
Location: Mandriva Control Center
Posts: 349
Default Re: pattern problem in c

ok........output is correct(I compiled in 'ancient tc' )
__________________
Vamsi Subhash
visit my blog at www.vamsisubhash.co.cc and taste a bit of IT!
vamsi360 is offline  
Old 13-12-2008, 09:06 PM   #12 (permalink)
learnhardy
 
Join Date: Oct 2008
Posts: 104
Wink Re: pattern problem in c

Qwerty!!! ur code works fine ........i got my answer thanks.
__________________
Newbie......
celebrate an ancient art .....
http://ambika.99k.org
ambika is offline  
Old 13-12-2008, 09:14 PM   #13 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: pattern problem in c

Use [code][/code] tags to post any format as accurately as possible. (The problem you said earlier, about making the forum post accept your spaces.)
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 14-12-2008, 10:38 AM   #14 (permalink)
Always confused
 
vamsi360's Avatar
 
Join Date: May 2008
Location: Mandriva Control Center
Posts: 349
Smile Re: pattern problem in c

Quote:
Originally Posted by QwertyManiac View Post
Use [code][/code] tags to post any format as accurately as possible. (The problem you said earlier, about making the forum post accept your spaces.)
I have been using the quick reply board most fo the times and haven't seen that. Thankyou for that. For you it shows PHP code. FIrst I thought all the answers you posted in remaining threads are in PHP. I think there is a confusion there. Use code only.
__________________
Vamsi Subhash
visit my blog at www.vamsisubhash.co.cc and taste a bit of IT!
vamsi360 is offline  
Old 14-12-2008, 11:04 AM   #15 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: pattern problem in c

Heh, I use it for syntax highlighting. They haven't installed any other language plug-ins.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem With Data Recovary Software Problem Stellar Phoenix njm Software Q&A 1 08-05-2007 12:31 PM
JAVA Pattern ??? vineetrocks2005 QnA (read only) 3 27-04-2007 03:45 PM
Problem!Problem!Problem Help Me November Cd And December dvd Doesnt Work yyy??? sourav_digit QnA (read only) 3 27-12-2006 02:33 PM
Time taken to download Virus pattern file using live update agnels Software Q&A 1 11-02-2006 07:47 AM
Grid pattern (photoshop tutorial) goobimama Tutorials 1 24-05-2005 11:43 AM

 
Latest Threads
- by gforz
- by soumya
- by Sujeet
- by icebags
- by Charan

Advertisement




All times are GMT +5.5. The time now is 03:03 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2