C console programs always start in the
main
function, so a minimal C app would look like this:
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
All executable code except global variable definitions (with or without simple assignments) must be inside a function.
So your line:
int sum , n1 , n2;
could be outside any function (but in this case is probably not a good idea as they dont; need to be global variables) but no other lines can be.
It's also a very good idea to indent your code - it makes it a lot more obvious what you expect to happen, and to match up brackets.
In addition, it's a good idea to always use curly brackets in
if
,
else
, and loops - particularly when you are just getting started.
So try like this:
#include <stdio.h>
int main()
{
int sum , n1 , n2;
scanf("%d %d" , &n1 , &n2);
if ((n1 == 10) || (n2 == 10))
{
printf("A number or their sum is 10");
}
else
{
sum = n1 + n2;
if (sum == 10)
{
printf("A number or their sum is 10")
}
else
{
printf("Numbers or their sum is not 10");
}
}
return 0;
}