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

Home Posts Topics Members FAQ

how to make a recursion count up and stop at its input

3 New Member
at the moment my code counts backwards by i need it to count forward while keeping the recursion. I cant get rid of it.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

void printcount(int);

int main(int argc, char *argv[]){

int sum =0;

if(argc == 2){ //checks if the arguments entered is exactly two
if(isdigit(*argv[1]) ==0){ // checks if second argument is a number
fprintf(stderr,"Usage: ./count+ number \n"); //if not usage error
return EXIT_FAILURE; // and end program $
} else if(isdigit(*argv[1]) !=0){ // if it is then stores the number
sscanf(argv[1],"%d",&sum);; //in sum
printcount(sum);
printf("%d\n",sum);
}
} else{
fprintf(stderr,"Usage: ./count+ number \n");// if argument not exactly
return EXIT_FAILURE; //two then usage error and end of program
}
return EXIT_SUCCESS;
}

void printcount(int n){

if(n>0){
printf("%d,");
printcount(n-1);
}
return;
}
Jul 28 '12 #1
1 2645
weaknessforcats
9,208 Recognized Expert Moderator Expert
Change your printcount function to not have av hard-coded subtract. Instead, add another argument which tells printcount whether to add or subtract.

Maybe this argument if positive is the limt of the recursion for add and if negative means to sutract.

Or maybe add two arguments. One says whether to add or subtract and the other says by how much.
Jul 28 '12 #2

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

Similar topics

0
by: Frnak McKenney | last post by:
Environment: OS Name Microsoft Windows 2000 Professional Version 5.0.2195 Service Pack 4 Build 2195 Microsoft Visual C# .NET 2003 Microsoft Development Environment 2003 Version 7.1.3088...
5
by: Tim Mulholland | last post by:
I'm trying to use 'compliant' HTML code in my asp.net pages, but VS.NET 2003 doesn't seem to think i should. Everytime i put a <br /> into my code, VS changes it back to <br> for me. I've played...
3
by: BJ | last post by:
Ever see those nifty sites that allow you to type text into a single or multi line text box and decrement from the maximum number of characters to 0? This lets the user know they are approaching...
5
by: Adrian Parker | last post by:
Say I have a form with several fields on it, some of which cause postbacks when changed. How can I stop the user from continuing to type data into the other fields while the server is still...
0
by: JT | last post by:
I have a web service that, until I started debugging locally, had no problems. After working out the kinks, I put it back on the web host where it had also worked. Now, when I build locally...
2
by: lavender | last post by:
I have one C programming problem: Enter value, 0 to stop: 15 26 45 0 List now : 15 26 45 0 37814140 Value to change : 26 Want to change with value: 45
0
tolkienarda
by: tolkienarda | last post by:
hi all is there a header file that allows a person to make a very simple version of the input field like the one used here on the scripts. somthing with the the options from B to the email link ...
3
by: smokinlabbit | last post by:
I'm trying to come up with a solution (but with no real direction to start with) where I'm trying to edit data in a td element of a table on the spot. What I want to do is when a td element...
4
sueb
by: sueb | last post by:
My query references a table in which I had to change the name of the primary index. So now, the query includes that new name instead of the old one. But when I run the query, it keeps asking for...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.