B
BobR
sumedh..... said:int main(){
int p=0;
Good, you inited 'p'. Problem: you never use this 'p'.
int j,n;
Bad, you didn't init them. Or document what they are!!
( hint: give them a better name.)
printf("Enter n");
scanf("%d",&n);
How do you know 'n' contains a valid value?
( I thought you wanted to be 'efficient'?)
j=n-1;
Where did 'j' come from? Oh, way up there! Why?
Why did you subtract one from 'n'? Document it!!
int j( n-1 ); // 'n' decremented by one, because I wanted to.
printf("\n\n");
printf("\t\t");
Why couldn't you combine those two?
k--;for( int p = 0; p < 2 * n - 1; p++ ){
for( int i = abs( j ); i < n; i++ )
printf("* ");
j--;
if( j >= 0 ){
printf("\n\t\t");
int k = n - 1 - j;
while( k > 0 ){
printf("\b\b");
}
k--;} // if(j)
else{
printf("\n\t\t");
int k = n - 1 - abs( j );
while( k > 0 ){
printf("\b\b");
}
} // else [if(j)]
} // for(p)
See, the first 'p' has never been touched. How 'efficient' is that?
return 0; // optional. give main() a proper burial.
} // main()
happy programming..
lets discuss on complexity in this respect...
can anyone suggest how can the program be made more efficient..
What Red said.