0% found this document useful (0 votes)
126 views11 pages

Algorithm Vs Pseudocode

The document provides a program to determine if a number is an Armstrong number, defined as a number equal to the sum of the cubes of its digits. It outlines the steps in pseudocode and includes a C program implementation to check for Armstrong numbers between 1 and 1000. Additionally, it describes the characteristics of algorithms and the purpose of pseudocode in programming.

Uploaded by

srib2183
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views11 pages

Algorithm Vs Pseudocode

The document provides a program to determine if a number is an Armstrong number, defined as a number equal to the sum of the cubes of its digits. It outlines the steps in pseudocode and includes a C program implementation to check for Armstrong numbers between 1 and 1000. Additionally, it describes the characteristics of algorithms and the purpose of pseudocode in programming.

Uploaded by

srib2183
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Write a programme to find given number is armstrong number or not ?

Armstrong number is a number that is equal to the sum of cubes of its digits.

Ex:
153
135333
1*1*1 = 1
5*5*5 = 125
3*3*3 = 27
Write a programme to find given number is armstrong number or not ?
Armstrong number is a number that is equal to the sum of cubes of its digits.

Ex:
153
135333
1*1*1 = 1
5*5*5 = 125
3*3*3 = 27
Step 1: Begin
Step 2: Declare Variables i, sum, r, temp, n
Step 3: Initialize sum to ‘0’
Step 4: User input value to store ‘n’ variable
Step 5: User input value also stored in ‘temp’ variable
Step 6: Check ‘n’ greater than ‘0’ to find the remainder when an ‘n’ is divided by
10 then store that remainder in to ‘r’ variable
else ‘n’ less than ‘0’ go to Step :10
Step 7: Then calculate ‘r’ cube, after that result add to ‘sum’ variable
Step 8: Calculate quotient of ‘n’ divided by 10, then result also stored in ‘n’ variable
Step 9: go to Step 6:
Step 10: if ‘sum’ variable value equal to the ‘n’ variable value print “Given number is
Armstrong”
if the ‘sum’ variable value not equal to the ‘n’ variable print “Given number is not
Armstrong”
Step 11: end
Step 1: Start
Step 2: Declare i, sum, r, temp, n
Step 3: Intialize sum=0
Step 4: input ‘n’
Step 5: initialize temp=n
Step 6: if n>0 goto step 7: otherwire goto step 11:
Step 7: r=n%10
Step 8: sum=sum+(r*r*r)
Step 9: n=n/10
Step 10: go to Step 6:
Step 11: if ‘temp’ equl to ‘n’ go to step 12: otherwise go to Step 13:
Step 12: print “Number is Armstrong”
Step 13: print “Number is not Armstrong”
Step 14: Stop
What is an Algorithm?
An algorithm is a set of well-defined instructions to solve a particular problem.

Characteristics of an Algorithm / Features of Algorithms:-


Not all procedures can be called an algorithm. An algorithm should have the following characteristics
• Unambiguous :-
Algorithm should be clear. Each of its steps (or phases), and their inputs / outputs should be
clear and must lead to only one meaning.
• Input :-
An algorithm should have 0 or more well-defined inputs.
• Output :-
An algorithm should have 1 or more well-defined outputs, and should match the desired
output.
• Finiteness :-
Algorithms must terminate after a finite number of steps.
• Effectiveness :-
Each step of the algorithm must be easily convertible into program statements
• Independent :-
An algorithm should have step-by-step directions, which should be independent of any
programming code.
Pseudo Code Definition:-
• Pseudo means 'False'
• Pseudo code means false code, that is not a actual code
• Instead of statements & Instructions pseudo code consists of
words & phrases.
• Pseudo code looks quite similar to a program, but is not a
program
• It has no syntax like any of the programming language & these
can't be compiled or interpreted by the computer.
• It is a methodology that allows the programmer to represent the
implementation of an algorithm.
How to write a Pseudo code?
• Start with the main goal / aim of the Pseudo code
• Arrange the sequence of tasks then write the code
• Use appropriate naming conventions that is simple and distinct
• Use also standard programming structures (eg: if, else, while etc..)
• Check whether all the sections of a Pseudo code is complete
Advantages of Pseudo code
• Advantages of Pseudo code
• One of the best approach to start implementation of an Algorithm
• It acts as a bridge between the program and the Algorithm / Flow chart
• Also works as a rough documentation, to develop the program
• The main goal of Pseudo code is to explain what exactly each line of a
program should do
#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,sum=0,temp;
clrscr();
printf("Enter any number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
printf("Given number is armstrong");
else
printf("Given number is not armstrong");

getch();
}
#include<stdio.h>
#include<conio.h> Armstrong numbers between 1 to 1000
void main()
{
int n=1,temp,r,sum,count=0;
clrscr();
printf("Armstrong numbers between 1 to 1000 are:");
while(n<=1000)
{
temp=n;
sum=0;
while(temp>0)
{
r=temp%10;
sum=sum+(r*r*r);
temp=temp/10;
}
if(n==sum)
{
printf("\n%d",n);
count++;
}
n++;
}
printf("\nAmstrong numbers between 1 to 1000 are: %d",count);
getch();
}

You might also like