473,473 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

print 1-50 as a block of 5 rows 10 columns using a function

8 New Member
o.k. so i can't program and this is child's play to most of your.
I am struggling with understanding functions. Here's what I have.#include <stdio.h>



Expand|Select|Wrap|Line Numbers
  1.     void row (int);
  2.     int main (void)
  3.  
  4. {
  5.     int x=41;
  6.     int i;
  7.  
  8.  
  9.     for (i=1; i<=x; i+=10)
  10.         printf("%d",i);
  11.     row (int j);
  12.  
  13. }
  14.  
  15.     void row(int j)
  16. {    
  17.     int j;
  18.     for (j=1;j<=41;j++)
  19.         printf("%d",j);
  20.         return 0;
  21. }
so i am trying to get
1 2 3 .... 10
11 12 13 .....20
21 22 23 .....30 up to 50.
I have to use a function.
I am trying to print the first column value,(i) pass it to the function,(row (int j)) add 1 to the value (i) (9 times) and then go back to main for my next value (i) wich will be 11 and so on.
Is this the correct approach? I've been at it for awhile now with no luck.
Feb 13 '08 #1
1 1357
Ganon11
3,652 Recognized Expert Specialist
Expand|Select|Wrap|Line Numbers
  1.     void row (int);
  2.     int main (void)
  3.  
  4. {
  5.     int x=41;
  6.     int i;
  7.  
  8.  
  9.     for (i=1; i<=x; i+=10)
  10.         printf("%d",i);
  11.     row (int j);
  12.  
  13. }
  14.  
  15.     void row(int j)
  16. {    
  17.     int j;
  18.     for (j=1;j<=41;j++)
  19.         printf("%d",j);
  20.         return 0;
  21. }
This code is wrong on several counts. I'll try and explain them all.

1) Why do you have printf statements in main if you're going to use your row function to print the numbers in nice rows?
2) When you call rows, you say int j - which (might?) create a new variable j that has been uninitialized.
3) In rows, you are passed j, but then you declare a new variable also named j, so the argument j is overwritten (or your code won't even compile). How are you going to print the value when you've hidden it from the function?
4) row is a void function, but you return 0.
5) main is an int function, but you don't return anything.

I have a feeling you didn't try and compile this code - or if you did, you saw all the warnings and didn't try to fix them. Get this code to compile first, then worry about the formatting - which, by the way, is going to be more difficult than just printing numbers in a for loop.
Feb 13 '08 #2

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

Similar topics

30
by: Martin Bless | last post by:
Why can't we have an additional 'print' statement, that behaves exactly like 'print' but doesn't insert that damn blank between two arguments? Could be called 'printn' or 'prin1' or 'prinn'...
23
by: stewart.midwinter | last post by:
No doubt I've overlooked something obvious, but here goes: Let's say I assign a value to a var, e.g.: myPlace = 'right here' myTime = 'right now' Now let's say I want to print out the two...
4
by: James | last post by:
Hello All, I have a stored procedure which will act like a main/controller script which will then invoke more stored procedures (~20). Basically, it looks something like below: -- start...
3
by: Marcus Bjorke | last post by:
I use a print link that causes a problem with Opera 7. The link looks like this <a href="javascript:parent.frames.mainFrame.print()">Print this page</a> I also used <a...
2
by: jamesthiele.usenet | last post by:
I recently ran into the issue with 'print' were, as it says on the web page called "Python Gotchas" (http://www.ferg.org/projects/python_gotchas.html): The Python Language Reference Manual says,...
2
by: Rainbow | last post by:
I know that print funciton will be available in the application for each type of file. My question is, can I print a file(any type, e.g. word, bmp, html, etc) in program? No printer dialog...
3
by: John Peterson | last post by:
Hello all! I'm at my wits end trying to search for what I assumed to be a relatively straightforward task. I have a Web application written in C#, and I have a button on the form that I want to...
2
by: kbperry | last post by:
Hi all, I am getting an error message when trying to use the P4 print command via the python api for perforce. Anytime that I run p4c.run("print","-q", eachFile), I keep getting an error...
2
by: Bill_DBA | last post by:
I have the following stored procedure that is called from the source of a transformation in a DTS package. The first parameter turns on PRINT debug messages. The second, when equals 1, turns on the...
11
by: JWest46088 | last post by:
I'm having difficulty trying to figure out how to print a text file from a hash table one line at a time. I have the text file read into the hash table and can print the text file all at once, but I...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.