![]() |
write algorithm
i have difficulty to write algorithm to following programs in c language
any one can help me ?? PROGRAM TO FIND SUM OF INDIVIDUAL DIGITS OF A NUMBER PHP Code:
PROGRAM TO FIND SUM AND AVERAGE OF GIVEN NUMBERS PHP Code:
third program witch FIND LCM AND GCD OF TWO INTEGERS PHP Code:
PHP Code:
PHP Code:
|
Re: write algorithm
Well, let's start with the first one. What does it do, and how does it do it? Can you explain in English how it works? From that we can then go on to write the algorithm.
|
Re: write algorithm
this is explanation for each program
1. To find the sum of individual digits of a given integer number . 2. To find the sum and average of a given array of integer numbers . 3. To find the GCD and LCD of given two integer numbers . 4. To find the reverse of a given integer number . 5. To find the sum of row elements , column elements and all elements of given 3x3 matrix of non-zero integers . . also i attached word file contain the program i want the algorithm for each one |
Re: write algorithm
writing algorithm isn't that much difficult. for e.g for the first program
step1: initialize the variables step2: modulo divide the number by 10 so as to get the individual digits. step3: save the number in a variable. step4: divide the number by 10. ...... Like this u can move on and since it is in a loop, U specify that "follow these steps until u get a single digit" r u can even use goto <step number>. This may not be the actual or proper algorithm for ur program. I just wrote it for an example. |
Re: write algorithm
I'd say the algorithm is at a higher level than that, hence the suggestion to start with an English description of what it does.
Note by "an English description of what it does" I don't mean just rehash the title. "To find the sum of individual digits of a given integer number" is just a title rehash, but the algorithm is how it does that. |
Re: write algorithm
Attachment removed and try to have the content in the post.
|
Re: write algorithm
hnaya, just one question: do you actually understand what the code is doing?
|
Re: write algorithm
hnaya, an observation. You opened with "i have difficulty to write algorithm to following programs in c language ". I asked: "What does it do, and how does it do it?" and in answer you said "i want the algorithm for each one"
Yes, I know you want the algorithm for each one. No, I'm not going to write it for you. (Someone else might though.) But I will help you write it, if you're willing to learn. So please answer my first question: "What does it do, and how does it do it?" (You may need to mention if you haven't got a clue how it works though; if you don't know that, you're definitely not going to be able to write the algorithm.) Lots of people post homework assignments expecting us (a) to write it for them and (b) not to be smart enough to realise that's what we're doing and (c) trustworthy enough that if we do realise, we won't write something for you that is plausible but significantly wrong. If that's what you're doing, you're not the first, you won't be the last, and it's very easy to spot (the key giveaways are the lack of willingness to learn and a "just give me the fscking answer" attitude). |
Re: write algorithm
The best way to learn algorithm is I think, to work it out in your khata....
At first, I also emphasised on writing the entire program...but what is more essential is to understand writing the algorithm....the other parts will come automatically... Just as xpi0t0s said...what will you do if you are not provided with a pc, just a notebook, a pen and you have been asked to draw a flow-chart of the key algorithm. Note that in the first program, the key algorithm is to distinguish the digits of a number....now how many ways can you do that.....draw all the possible flow-charts...and always stay greedy of drawing one more...then I think it will be perfect. Similarly, try to find out what the other key algorithms are in the remaining programs. |
| All times are GMT +5.5. The time now is 12:58. |