Answer:
There is no need to make an algorithm for this simple problem. Just add the two numbers by storing in two different variables as follows:
Let a,b be two numbers.
c=a+b;
print(c);
But, if you want to find the sum of more numbers, you can use any loop like for, while or do-while as follows:
Let a be the variable where the input numbers are stored.
while(f==1)
{
printf(“Enter number”);
scanf(“Take number into the variable a”);
sum=sum+a;
printf(“Do you want to enter more numbers? 1 for yes, 0 for no”);
scanf(“Take the input into the variable f”);
}
print(Sum)
Explanation:
hi there answer is given mar me as brainliest
Answer:
import java.util.Scanner;
public class num10 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the numbers to add up. enter 999 to stop");
int num = in.nextInt();
int sum = 0;
while (num!=999){
sum = sum+num;
System.out.println("Enter the next number");
num = in.nextInt();
}
System.out.println("The sum is: "+sum);
}
}
Explanation:
The application is implemented in Java
A while loop is used to continously prompt user for inputs. The condition of the while loop is while (num!=999)
When the number 999 is entered, it displays the sum which is initialized to 0
Answer:
Following are the correct code to this question:
short_names=['Gus','Bob','Zoe']#defining a list short_names that holds string value
print (short_names[0])#print list first element value
print (short_names[1])#print list second element value
print (short_names[2])#print list third element value
Output:
Gus
Bob
Zoe
Explanation:
- In the above python program code, a list "short_names" list is declared, that holds three variable that is "Gus, Bob, and Zoe".
- In the next step, the print method is used that prints list element value.
- In this program, we use the list, which is similar to an array, and both elements index value starting from the 0, that's why in this code we print "0,1, and 2" element value.