[C/C++] If you run my code what output

If you run my code what output do you get ?

This is mine:

My code:

// Created by Paul A. Gureghian in May 2020. //
//This C program takes two integers and calculates the sum. //

// Start of program. //

// Import libraries. //
#include <stdio.h>

// Define the main(). //
int main()
{
    int i, j, sum;
    scanf("Enter 1'st integer: %d", &i);
    scanf("Enter 2'nd integer: %d", &j);

    sum = i + j;

    printf("Sum is: %d\n", sum);
    return 0;
}

// End of program. //

You are not quite using scanf() correctly. You can read documentation here.

See my modified example:

// Created by Paul A. Gureghian in May 2020. //
//This C program takes two integers and calculates the sum. //

// NOTE:
// This comment is ok without closing
/* This comment needs to be closed */

// Start of program. //

// Import libraries. //
#include <stdio.h>

// Define the main(). //
int main() {
  int i, j, sum;
  printf("Enter 1st integer: ");
  scanf("%d", &i);
  printf("Enter 2nd integer: ");
  scanf("%d", &j);

  sum = i + j;

  printf("Sum is: %d\n", sum);
  return 0;
}

Unrelated note - with the single line comment characters, //, it is not necessary to put those characters at the start and end of a comment line. However, if you instead use the comment characters /*, you do need to close the comment with */.

1 Like

That worked. thanks.

1 Like