
pseudocode that prints numbers between 100
#1
Posted 22 January 2016 - 02:42 AM

#2
Posted 22 January 2016 - 03:32 AM

Hey guys i am new in C programming. i need to write a pseudo code that prints numbers between 100 in descending order.That is, from 100 to 0.please tell me if i am correct or not. Here is my pseudo code; and thanks.BEGINc= 100while (c <= 100)DOc= c-1END DOEND
Hey David,
The method of writing pseudo code, is usually writing informal high level code, which is easily understandable by humans but following structural conventions and logic of an actual programming language. I mention this because I noticed you included aspects such as "END", "BEGIN" and "DO" which isn't necessary because it looks like you're focusing on syntax. When writing pseudo code, you want to concentrate solely on the logic of what you are trying to achieve irrelevant of the language.
As for the logic you're kinda almost there but your while condition would be considered incorrect for a descending order number loop.
--
int c = 100 // Instantiating in pseudo code is not necessary, although I am instantiating c as an int (So logically I can see that I will be working with a variable named c which is of an integer/number type and not some other data type. I have also assigned the value 100 because I know this variable see will require starting at 100.)
while(c >= 0) // You will notice the logical operator is the >= because I want the loop to continue executing for as long as c is greater than 0 because we are subtracting down from 100.
print c; // Printing variable c to the screen (Notice I don't use a language specific way of printing to screen, all I am concerned with is printing to screen, not with how it is achieved in a specific programming language)
c = c - 1 // Decrement c by 1
end while
print c; // I print C for the last time to display 0, because it would not print the value 0 in the loop. This is just "one" way of doing it, you can go about order of printing to screen in several different way
---
That's basically it... Let's look at the logic in your code:
I really hope I have explained the logic in a understandable way... Please let me know if you require any further explanation. I have also included a cleaner version of my pseudo code without comments and explanations.
int c = 100 while (c >= 0) print c c = c - 1 end while print c
A side tip on working with loops; the best thing you can do is step through your logic 1 line at a time in the order that your computer would execute the code while keeping in mind the value of all your variables on that line.
Peace Out
Similar Topics
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
As Featured On:






