Я помогал юношам с программированием на Си, чего я не делал более 4-5 лет, и я забыл немало синтаксисов.Вставка ниже кода
#include <stdio.h>
#include <conio.h>
######## Example 1 ########
divide(float x,float y)
{
return (x/y);
}
void main()
{
int z;
z=divide(10.0,2.0);
printf("%d",z);
main.c:15:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
divide(float x,float y)
^~~~~~
main.c: In function ‘main’:
main.c:24:1: error: expected declaration or statement at end of input
printf("%d",z);
^~~~~~
Когда я пытаюсь ввести явный тип возврата в виде числа с плавающей запятой в ответ (x / y)
######## Example 2 ########
divide(float x,float y)
{
return (float)(x/y);
}
void main()
{
int z;
z=divide(10.0,2.0);
printf("%d",z);
}
main.c:15:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
divide(float x,float y)
^~~~~~
main.c: In function ‘main’:
main.c:24:1: error: expected declaration or statement at end of input
printf("%d",z);
^~~~~~
######## Example 3 ########
divide(float x,float y)
{
return (float) (x/y);
}
void main()
{
divide(10.0,2.0);
}
main.c:15:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
Program finished with exit code 5
Press ENTER to exit console.
The last code run returned a blank. I'm guessing it's returning a garbage value.
Can somebody please help me out with this?
https://www.onlinegdb.com/online_c++_compiler# Я использовал вышеуказанный веб-сайт для запуска своего кода, если компилятор чем-нибудь поможет.Спасибо!