为什么会报错?error:fuction definition is not allowed here

拉普拉斯妖 2019-12-15 11:00:44
#include <stdio.h> int sd(int); int main() { int sd (int b) { if(b>1) { b*b-1; printf("100与100–1的乘积值为%d",b*b-1); } else { printf("数值过小"); } } int ret=sd(100); return 0; }
...全文
1251 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
自信男孩 2019-12-16
  • 打赏
  • 举报
回复
C语言不支持函数嵌套定义~
棉猴 2019-12-15
  • 打赏
  • 举报
回复
引用 2 楼 拉普拉斯妖 的回复:
谢谢,不过我想知道为什么会报错

main()是一个函数,不要在函数中定义函数
一拳_超人 2019-12-15
  • 打赏
  • 举报
回复
b*(b-1)才能得到100与100-1乘积,优先级问题 递归函数不要写在main函数里

#include <stdio.h>
int sd(int);
int main()
{
    int result,b;
    scanf("%d",&b);
    result= sd(b);
    if(result)
    printf("%d与%d-1乘积=%d",b,b,result);
    else printf("数值过小");
    return 0;
}
int sd(int b)
{
    if (b>1)
    {
        return b*(b - 1);
    }
    else
    {
        return 0;
    }
}
拉普拉斯妖 2019-12-15
  • 打赏
  • 举报
回复
谢谢,不过我想知道为什么会报错
棉猴 2019-12-15
  • 打赏
  • 举报
回复
代码写的不错,只是稍微改一下就可以啦!
#include <stdio.h>
int sd(int);
int main()
{

int ret = sd(100);

return 0;
}
int sd(int b)
{
if (b>1)
{
b*b - 1;
printf("100与100–1的乘积值为%d", b*b - 1);
return b*b - 1;
}
else
{
printf("数值过小");
return 0;
}

}

VS2015调试结果
Delphi 7.1 Update Release Notes=======================================================This file contains important supplemental and late-breakinginformation that may not appear in the main productdocumentation, and supersedes information contained in otherdocuments, including previously installed release notes.Borland recommends that you read this file in its entirety.NOTE: If you are updating a localized version of Delphi 7, visit the Borland Registered User web site to obtain a localized readme file that may contain important late- breaking information not included in this readme file.IMPORTANT: Delphi must be closed before installing this update. =====================================================CONTENTS * INSTALLING THIS UPDATE * UPDATING LOCALIZED VERSIONS OF DELPHI 7 * KNOWN ISSUES * ISSUES ADDRESSED BY THIS UPDATE - IDE - CORE DATABASE - DATASNAP - DBGO (ADO COMPONENTS) - dbExpress - dbExpress COMPONENTS AND DB VCL - dbExpress CORE DRIVER AND METADATA - dbExpress VENDOR ISSUES - dbExpress CERTIFICATION - WEB SNAP - ACTIVEX - COMPILER - RTL - VCL - THIRD PARTY - BOLD FOR DELPHI * VERIFYING THAT THE UPDATE WAS SUCCESSFUL * FILES INSTALLED BY THIS UPDATE =======================================================INSTALLING THIS UPDATE* This update can not be applied to Delphi 7 Architect Trial version. * This update can not be removed after it is installed.* You will need the original Delphi 7 installation CD available to install this update.* To install this update from the CD, insert the CD, and launch the d7_ent_upd1.exe file appropriate for your locale.* To install this update from the Web, double-click the self-executing installation file and follow the prompts. * The Delphi 7 documentation PDF files are available on the update CD.========================================================UPDATING LOCALIZED VERSIONS OF DELPHI 7* This update can be applied only to the English version of Delphi 7. There are separate updates for the German, French and Japanese ver

70,012

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧