Write an algorithm and draw a corresponding flow chart to print the sum of the digits of a given number 10m Dec2005
An algorithm is a finite set of steps defining the solution of a particular problem. An algorithm is expressed in pseudo code – something resembling C language or Pascal, but with some statements in English rather than within the programming language
- A sequential solution of any program that written in human language, called algorithm.
- Algorithm is first step of the solution process, after the analysis of problem, programmers write the algorithm of that problem.
Pseudo code:
- Input a Number
- Initialize Sum to zero
- While Number is not zero
- Get Remainder by Number Mod 10
- Add Remainder to Sum
- Divide Number by 10
- Print sum
Detailed Algorithm:
Step 1: Input N
Step 2: Sum = 0
Step 3: While (N != 0)
Rem = N % 10;
Sum = Sum + Rem;
N = N / 10;
Step 4: Print Sum
Flowchart:-
Q Write a recursive program to find the G.C.D. of the two given numbers. 10m Dec2005
Solved program can be found on this link http://cssimplified.com/c-programming/a-c-program-to-find-the-gcd-of-given-numbers-using-recursion