Back to articles
Basic Programs Every Beginner Must Know (LCM, Sum, Factorial)

Basic Programs Every Beginner Must Know (LCM, Sum, Factorial)

via Dev.to TutorialAbishek

These are the most important beginner problems asked in interviews and tests. Let’s understand them with logic + flow + code in 3 languages. 1. Sum of N Numbers Find the sum from a starting number to an ending number. Python output JAVA import java.util.Scanner ; public class SumN { public static void main ( String [] args ) { Scanner sc = new Scanner ( System . in ); int start = sc . nextInt (); int end = sc . nextInt (); int result = 0 ; while ( start <= end ) { result += start ; start ++; } System . out . println ( result ); } } JavaScript let start = 1 ; let end = 10 ; let result = 0 ; while ( start <= end ) { result += start ; start ++ ; } console . log ( result ); 2. LCM (Least Common Multiple) Find the smallest number divisible by both numbers. Python output JAVA import java.util.Scanner ; public class LCM { public static void main ( String [] args ) { Scanner sc = new Scanner ( System . in ); int a = sc . nextInt (); int b = sc . nextInt (); int max = ( a > b ) ? a : b ; while

Continue reading on Dev.to Tutorial

Opens in a new tab

Read Full Article
3 views

Related Articles