473,379 Members | 1,190 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Square of asterisk in c

Geekibz
12
Hi.I want to print out a 5 by 5 square of asterisks in c using nested for loops.I tried but my code(see below) resulted in an infinite loop.Pls help.
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. main()
  3. {
  4. int x,y,c=5;
  5. for(x=c;x<=c;x--)
  6. {
  7.     for(y=c;y<=c;y--)
  8.         printf("*");
  9.  
  10. }
  11. printf("\n");
  12. }
Feb 2 '08 #1
3 11506
hi geek biz
in u r code u r decrementing the x value which is always less than c and hence it falls in to infinite loop.

try this
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. main()
  3. {
  4.     int x, y, c=5;
  5.     for (x=c; x>0; x--)
  6.     {
  7.         for (y=c; y>1; y--)  //changed this line
  8.             printf("*");    // changed this line
  9.         printf("*\n");      // changed this line
  10.     }
  11.     printf("\n");
  12. }
Feb 2 '08 #2
Geekibz
12
Thanx.Works fine.how about modifying that to printout a pyramid of asterisk?I intend to use if -else statements.Is there an easier way out?
Feb 4 '08 #3
sicarie
4,677 Expert Mod 4TB
Yes. Yes there is.
Feb 4 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: sarmin | last post by:
Hi Pythoners... It seems to me the Asterisk (*) sign in python means many things... if a python code line looks like this: def__init__(self, func, *param): bla bla bla... and then u have...
1
by: sarmin kho | last post by:
Hi Pythoners... I am definitely confused with the use of asterisk (*) sign in python... I quoted the following code from 'python cookbook' text book page 223 about 'running functions in the...
2
by: Marco | last post by:
Hi all, I saw the following line in a C source. what's the asterisk * mean? Thank you! fprintf(conn_out, "%.*s\r\n", (int)(strlen(buf + 1) - 1), buf + 1);
3
by: Robert M | last post by:
Hello, I am having a problem when I enter a new row using data grid footer and the data contains asterisk ('). I can use replace function, and it will not crash the program but it shows 2...
2
by: Evan | last post by:
I am trying to put an asterisk in the Label text property but the asterisk doesn't show up in the correct place. If I enter "* hello" in the text property (using the designer property pages) the...
5
by: punkybrewster | last post by:
My task is to write a program that reads in from the user the size of the sides of a square and prints a hollow square of that size in asterisks and spaces. A nested loop should be done. An example...
0
by: selvarani | last post by:
Hi all, I am a newbie to Asterisk and PHP. I have installed wamp5_1.4.3 and working with PHP on this. I would like to write a PHP script to interact with asterisk. Where are the Manager API's...
1
by: striker07 | last post by:
Someone help me how can i display a diamond shaped asterisk correctly pls. correct my program this is my code: Dim ctr, space, asterisk As Integer For ctr = 1 To 9 Step 2 For space = (9...
2
by: Coll | last post by:
I'm working with a form & a query that allows the user to filter the data using several combo boxes. One of the combo boxes allows them to select the first letter of a a particular field, and it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.