Challenge 3: Count the Apples! 🚀
Welcome to this challenge! Work with Robo 🤖 to solve this problem step-by-step using algorithms and flowcharts.
🎬 The Story
Robo has $3$ apples in one bag and $5$ apples in another. Help Robo read both numbers, add them together, and display the total sum.
📝 The Algorithm
- Start (Begin the program)
- Read Number1 and Number2 (Input)
- Add Number1 and Number2 and store the result in
sum(Process) - Display sum (Output)
- Stop (End the program)
📊 The Flowchart
Notice the introduction of the Process Rectangle for calculations.
💻 From Flowchart to Code
Here is how to add two input numbers in Python, Java, and C:
- Python
- Java
- C
# Read two numbers (converted from text to integers)
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
# Add them
total = num1 + num2
# Display result
print("Sum:", total)
import java.util.Scanner;
public class AddNumbers {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter first number: ");
int num1 = sc.nextInt();
System.out.print("Enter second number: ");
int num2 = sc.nextInt();
// Calculate sum
int sum = num1 + num2;
// Display result
System.out.println("Sum: " + sum);
}
}
#include <stdio.h>
int main() {
int num1, num2, sum;
printf("Enter first number: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);
// Calculate sum
sum = num1 + num2;
// Display result
printf("Sum: %d\n", sum);
return 0;
}