89.7k views
2 votes
Write a short code in micro controller about adding two numbers

User M Rajoy
by
8.3k points

1 Answer

5 votes

Answer:#include <stdio.h>

int main() {

int num1, num2, sum;

// Read the first number from input

printf("Enter the first number: ");

scanf("%d", &num1);

// Read the second number from input

printf("Enter the second number: ");

scanf("%d", &num2);

// Add the two numbers

sum = num1 + num2;

// Display the result

printf("The sum of %d and %d is %d", num1, num2, sum);

return 0;

}

Step-by-step explanation:

This code declares three integer variables num1, num2, and sum. It reads two numbers from the user using scanf() function, adds them using the + operator, and stores the result in the sum variable. Finally, it displays the result using the printf() function.Note that the exact code may vary depending on the microcontroller being used and the programming language being used to code it.

User TimeTrap
by
7.9k points