Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Nov 9th, 2005, 1:11 PM   #1
haniunited
Newbie
 
Join Date: Nov 2005
Posts: 1
Rep Power: 0 haniunited is on a distinguished road
Thumbs up Troules with a triangle? ( how good is my code so far?)

i am single 43 years old man... extreme photoshpper
just decided to get myself into programming.. so i just arrived the 'for' function in my 317 pages book
i just cant figure out how do this :
( its part of a questino not a full one )

The users enters a number
which will spicify the number of rows and the value of the middle number

like
lets say the user entered the number '7'
the shape will be like this



7 \\ 12 spaces from the left
6_7_6 \\ 10 spaces from the left
5_6_7_6_5 \\ 8 spaces from the left
4_5_6_7_6_5_4 \\ 6 spaces from the left
3_4_5_6_7_6_5_4_3 \\ 4 spaces from the left
2_3_4_5_6_7_6_5_4_3_2 \\ 2 spaces from the left
1_2_3_4_5_6_7_6_5_4_3_2_1 \\ 0 spaces from the left
Note: the symbol '_' means space

we must use 'for' functions three or two ones

anyone knows ? please share


so far here is what i have done

THIS :

#include<stdio.h>

int main()
{
    int k,h,i,j,number;

    printf("Please enter a number: ");
    scanf("%d",&number);

    for(i=number; i > 0; i--) {
        /* print leading spaces */
        for(j=0; j < (i-1) * 2; j++) {
            printf(" ");
        }
             for(k=1; k < number; k++){
             printf("%d",k);}
             
             for(h=number;h>=number;h--)
             {
             if(h!=1)
             printf(" %d,",h);
             else
             printf("%d",h);
             }
             
             
        /* need a loop or 2 loops or something here */
        printf("%d \n", i);
    }

    return 0;
}


OR

THIS

#include<stdio.h>
void main ()
{
int i,j,t,n;

printf("Please enter a number\n");
scanf("%d",&n);
x=(n-i)*2
for(i=1;i<=n;i++)
{
for(j=1;j<=x;j++)
printf(" ");

for(t=1;t<=n;t++)
printf("%d",t);
for(k=n;k>=1;k--)
{
if(k!=1)
printf("SPACE HERE THEN %d",n);
else
printf("%d",n)
{
printf("\n");
}
}
haniunited is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:16 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC