Is any semantically correct and syntactically correct C program an algorithm?
algorithm, c, data-structures
Solution
You tell your professor that he better stops splitting hair if he doesn't even know the correct terminology (so from this point, his question doesn't make sense, but anyway...).
An "algorithm" is conceptually different from a program. So the answer to
Is any semantically correct and syntactically correct C program an algorithm?
is no, since a program is not the same as an algorithm - a program is... a program. An algorithm is a specific manifestation of the solution of a problem which is language-agnostic (i. e. it can be worded in a quite generic way). A program is a language-dependent concrete implementation of an algorithm (which is, in C, due to the "as-if" rule and compiler optimizations, need not actually be the same as the algorithm, it's only required to emulate it).
One more comment:
the infinite loop isn't semantically correct
Well, it is. Of course one does not simply solve the halting problem, but it doesn't mean that an infinite loop would be "semantically incorrect". A program is semantically incorrect when it does something else than that you would expect. Unless you expect your program to do something else than hanging when you write `while (1) { }`, there's no problem.
Whether the concept of an infinite loop is considered an algorithm is another question. Generally, an instruction sequence that never terminates is not considered an algorithm, and probably that's what your professor was talking about. According to Wikipedia:
More precisely, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function.
(emphasis mine)
Problem
" An algorithm is defined to be a finite sequence of operations which whn executed will accomplish a specific task" with this definition. Can we say that ANY syntactically and semantically correct C program is also an algorithm? my answer is TRUE, however my professor said the answer is FALSE, so did my blockmate. The counter example they used was ``` while(1) { } ``` and ``` printf("%s","blahblah"); ``` the infinite loop isn't semantically correct, while the printf() accomplishes a task so it is an algorithm. Because you can use a loop and putchar() instead of printf(); So who do you guys think is right?