Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually * was replaced by " " ;
If we can solve it using abs() then please explain it;

****1****
***1*1***
**1*2*1**
*1*3*3*1*
1*4*6*4*1
*1*3*3*1*
**1*2*1**
***1*1***
****1****


What I have tried:

#include<stdio.h>
#include<conio.h>

   int main()
   {
       int i,j,c=0;

       for(i=5;i>=1;i--)
       {
           for(j=1;j<=9;j++)
           {
               if( (j>= i) && (j<= (c+i) )  )
               {
                   printf("*");

               }
               else
               {
                   printf(" ");
               }
           }
           c=c+2;
           printf("\n");
       }

       c=6;

           for(i=2;i<=5;i++)
       {
           for(j=1;j<=9;j++)
           {
               if( (j>= i) && (j<= (c+i) )  )
               {
                   printf("*");

               }
               else
               {
                   printf(" ");
               }
           }
           c=c-2;
           printf("\n");
       }



       getch();
       return 0;
   }
Posted
Updated 4-Aug-16 13:49pm
v3
Comments
nv3 4-Aug-16 18:16pm    
None of your printf statements prints a number. So how do you expect your code to print the desired pattern? Also, look at the expression in the if-statements:

j>=i && j<=c+i

With c being always positive this expression is always false.

My suggestion: Run through your code with a debugger and see what it does, line by line. And compare that with what you were expecting. You will soon see, where the various mistakes are.
jeron1 5-Aug-16 11:38am    
How about

#include<stdio.h>
#include<conio.h>

int main()
{
printf("****1****\n");
printf("***1*1***\n");
printf("**1*2*1**\n");
printf("*1*3*3*1*\n");
printf("1*4*6*4*1\n");
printf("*1*3*3*1*\n");
printf("**1*2*1**\n");
printf("***1*1***\n");
printf("****1****\n");
}
See? No abs() involved!

;-)

1 solution

This is HomeWork, so only advices.
The pattern is:
Pascal's triangle - Wikipedia, the free encyclopedia[^]
-try to solve the problem as 2 problems:
- solve the computing of each rows values.
- Solve the presentation
you need to remember the previous row to compute the next one.
Nota: abs() is not needed.
 
Share this answer
 
v2
Comments
CPallini 5-Aug-16 3:02am    
5.
Patrice T 5-Aug-16 4:56am    
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900