Your Code:
Code:
#include <stdio.h>
#include <conio.h>
int multiply( int x, int y )
{
int product;
product = x * y;
return product;
}
int main()
{
clrscr();
int ans;
/*
This is not logically correct, you have to declare all variables before you
use any program statement or a built-in function.
*/
ans = multiply(5, 2);
printf("The product of 5 and 2 is %d", ans);
return 0;
getch();
/*
This is not reachable anymore because you already returned the program control to the OS
*/
}
A more optimized code with Comments
Code:
/*
Pre-processor Directives Declaration
*/
#include <stdio.h>
#include <conio.h>
/* User-defined Functions */
int multiply( int x, int y );
/* Function main() */
int main() {
/*
user defined variables declaration part.
*/
/*
main program statements
*/
clrscr();
printf("The product of 5 and 2 is %d", multiply(5,2));
/*
wait for user to press any key
*/
getch();
return 0;
}
int multiply(intx, int y){
return(x*y);
}
Optimized Code without Comments:
Code:
#include <stdio.h>
#include <conio.h>
int multiply( int x, int y );
int main() {
clrscr();
printf("The product of 5 and 2 is %i", multiply(5,2));
getch();
return 0;
}
int multiply(intx, int y){
return(x*y);
}