If it’s true, then we add the value present inside variable count to previous value present in variable sum.Īfter the control exits while loop we display the value present in variable sum – which has the sum of all the odd numbers from 1 to user entered number. Inside while loop we check for the condition, count%2 != 0. For each iteration of while loop we increment the value of count by 1. In the post we saw how we can use the command factor to find whether a number is prime of not. While loop keeps iterating until value of count is less than or equal to value of user input number. Linux script to find prime numbers in a range of numbers. Since we are checking for odd numbers from 1 to user entered number, we assign value of variable count to 1. YouTube Link: Logic To Find Sum of All Odd Numbers From 1 To N, using While loop MATLAB is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |