OneBite.Dev - Coding blog in a bite size

add two numbers in C

Code snippet on how to add two numbers in C

  // Declare two integers
  int a = 5;
  int b = 7;
 
  // Add the two integers
  int sum = a + b;
  
  // Output the sum to the console
  printf("Sum of a and b is %d\n", sum);

This code sample adds two integers (5 and 7) and prints out the sum. First, two int variables, a and b, are declared and set to the numbers 5 and 7 respectively. Then, another int variable, sum, is declared and set to the sum of a and b. Finally, printf is used to output the sum integer to the console.

c