473,414 Members | 1,628 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,414 software developers and data experts.

plz find the error

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. using namespace std;
  3. int hcf(int,int);
  4. int main(){
  5.     int x,y,div,dividend;
  6.     cout<<"enter two numbers:\n";
  7.     cin>>x>>y;
  8.     if(x>y){
  9.         div=y;
  10.         dividend=x;
  11.     }
  12.     else{
  13.         div=x;
  14.         dividend=y;
  15.     }
  16.  
  17.     int q=hcf(div,dividend);
  18.     cout<<"\ngcd is:"<<q;
  19. }
  20. int hcf(int div,int dividend){
  21.     int r;    
  22.     r=dividend%div;
  23.     cout<<r<<" "<<div<<"\n ";
  24.     if(r!=0)
  25.         hcf(r,div);
  26.     else
  27.  
  28.         return(div);    
  29. }

here it is not giving correct output for 2 numbers. whose gcd is 1.Can u plz debug it and tell me how exactly recursion works
Feb 17 '08 #1
1 1064
sicarie
4,677 Expert Mod 4TB
I would actually recommend the explanation of how recursion works before debugging - both Google and Wikipedia have good articles on this. You have the internet at your fingertips, and those resources were created to help find and explain things like that.

As for debugging, why would someone else do your homework for you? Especially when you admittedly have a less than clear understanding of how your program works. This is why you should develop a precise algorithm before coding your project - if you just jump into the coding, you will get stuck and confused.
Feb 17 '08 #2

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

Similar topics

1
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
0
by: Andrei Ivanov | last post by:
Hello, it seems my postgresql data has somehow become corrupted (by a forced shutdown I think): psql template1 -U shadow Password: ERROR: nodeRead: did not find '}' at end of plan node...
1
by: Andrei Ivanov | last post by:
Hello, it seems my postgresql data has somehow become corrupted (by a forced shutdown I think): psql template1 -U shadow Password: ERROR: nodeRead: did not find '}' at end of plan node...
2
by: Zenobia | last post by:
Hi, Below is a bit of code from ASP.NET Unleashed which gives an error and I can't figure out why. It uses the Authors table from the standard Pubs database. The error message is...
7
by: tehn.yit.chin | last post by:
I am trying to experiment <algorithm>'s find to search for an item in a vector of struct. My bit of test code is shown below. #include <iostream> #include <vector> #include <algorithm>...
0
by: Curious | last post by:
Hi, I'm not sure if this is the right place to post such command issues. If you know a better forum where people respond to messages fairly often, please let me know! Anyway, would appreciate...
3
by: Lance Wynn | last post by:
Hello, I am receiving this error when trying to instantiate a webservice component. I have 2 development machines, both are XP sp2 with VS 2008 installed. On one machine, the code works fine. On...
2
by: Olumide | last post by:
Hello, I've got this nice inner class that I'm holds a set of "FrontPoint" objects as shown below. Unfortunately, the find and insert methods trigger massive C2784 errors. Would someone please...
11
by: ezechiel | last post by:
hi, I have the following error on a win server: "Invalid Top Directory perl/lib/file/find.pm line 598 Here's the code and I'll explain what I found until now: #!/usr/bin/perl # use strict;...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
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...
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
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...

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.