1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

C programming star pattern

Discussion in 'C' started by abhishekbnrj459, Mar 9, 2012.

  1. abhishekbnrj459

    abhishekbnrj459 New Member

    Joined:
    Mar 9, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    How to print the following pattern in c???please give me the codes
    Code:
     *           *
        *     *
           *
       *      *
    *            *
    
     
    Last edited by a moderator: Mar 9, 2012
  2. abhishekbnrj459

    abhishekbnrj459 New Member

    Joined:
    Mar 9, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    * *
    * *
    *
    * *
    * *
    how to print this pattern??
     
  3. dearvivekkumar

    dearvivekkumar New Member

    Joined:
    Feb 21, 2012
    Messages:
    29
    Likes Received:
    5
    Trophy Points:
    0
    Code:
    /*
    
     *           *
        *     *
           *
       *      *
    *            *
    
    */
    
    #include <stdio.h>
    
    void displayStar()
    {
    	int starCount = 0;
    	bool invalid = true;
    	while(invalid)
    	{
    		printf("Enter odd number of start you wants in row/column -> "); 
    		scanf("%d", &starCount);
    		if((starCount % 2 == 0) || (starCount > 100) || (starCount <= 0) ) {
    			printf("Please Enter any ODD number in range of 3 to 100\n");
    			invalid = true;
    			fflush(stdin);
    		}
    		else{
    			invalid = false;
    		}
    	}
    
    	int innerCount = 0;
    	int outerCount = 0;
    	for(outerCount = 0; outerCount < starCount; outerCount++)
    	{
    		for(innerCount = 0; innerCount < starCount; innerCount++)
    		{
    			if((innerCount == outerCount) || 
    			   (innerCount == starCount - outerCount -1)) 
    			{
    				printf("*");
    			}
    			else
    			{
    				printf("  ");
    			}
    		}
    		printf("\n");
    	}
    }
    
    int main(int argc, char* argv[])
    {
    	displayStar();
    	return 0;
    }
    
     
    shabbir likes this.
  4. dearvivekkumar

    dearvivekkumar New Member

    Joined:
    Feb 21, 2012
    Messages:
    29
    Likes Received:
    5
    Trophy Points:
    0
    Code:
    /*
    
    * *
    * *
    *
    * *
    * *
    
    */
    
    #include <stdio.h>
    
    void displayStar()
    {
    	int starCount = 0;
    	bool invalid = true;
    	while(invalid)
    	{
    		printf("Enter odd number of start you wants in row/column -> "); 
    		scanf("%d", &starCount);
    		if((starCount % 2 == 0) || (starCount > 100) || (starCount <= 0) ) {
    			printf("Please Enter any ODD number in range of 3 to 100\n");
    			invalid = true;
    			fflush(stdin);
    		}
    		else{
    			invalid = false;
    		}
    	}
    
    	int innerCount = 0;
    	int outerCount = 0;
    	for(outerCount = 0; outerCount < starCount; outerCount++)
    	{
    		for(innerCount = 0; innerCount < starCount; innerCount++)
    		{
    			if((innerCount == outerCount) || 
    			   (innerCount == starCount - outerCount -1)) 
    			{
    				printf(" * ");
    			}
    			else
    			{
    				printf("");
    			}
    		}
    		printf("\n");
    	}
    }
    
    int main(int argc, char* argv[])
    {
    	displayStar();
    	return 0;
    }
    
     

Share This Page