简体   繁体   English

我的代码有问题,我不确定我是否写对了

[英]i have a problem with my code and i'm not sure if i even wrote it correctly

so i'm practicing c and i built a program that says if its prime number or not and i tried to execute it but it wont work it doesnt shows me the output oh and im still new to this i started learning c one week ago.所以我正在练习 c 并且我构建了一个程序,它说它是否为质数,我试图执行它但它不会工作它没有向我显示输出哦,我仍然是新手,我一周前开始学习 c。

i dont know how to fix this.我不知道如何解决这个问题。

#include <stdio.h>

void Num();

int main()
{
  void Num();

  return 0;
}

void Num()
{
  int n, i, flag = 0;

  printf("Enter a num: ");
  scanf("%d", &n);

  for(i = 1; i <= 10; i++)
  {
    for(n = 1; n <= 10; n++)
    {
      flag = 1;
    }
  }

  if( flag == 1)
  {
    printf("its not the prime num ");
  } else{
    printf("its the prime num" );
  }
}

it wont even show the printf output它甚至不会显示 printf 输出

You need to go back to the basics (this means: reading a good C book before diving in).您需要回归基础(这意味着:在深入研究之前阅读一本好的 C 书)。 You are confusing declaration and calling of functions.您混淆了函数的声明调用

int main()
{
  void Num();

  return 0;
}

main contains two statements: main包含两个语句:

  1. A local (re)declaration of Num as a function without return value.Num本地(重新)声明为没有返回值的函数。
  2. A return statement.一个return语句。

Since you want to call Num rather than redeclaring it, you need to use the function call syntax:由于要调用Num而不是重新声明它,因此需要使用函数调用语法:

int main()
{
  Num();
  return 0;
}

This is just the first step, however.然而,这只是第一步。 Your Num function does not perform the correct actions to determine primality.您的Num函数没有执行正确的操作来确定素数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 学校课程测试无法正确覆盖我的代码,我不确定为什么 - School program tests not covering my code correctly and I'm not sure why 我不知道为什么我在 C 中的日志问题一直给我 0 或 -9223372036854775808。 我认为这是我正在使用的变量类型,但我不确定 - I have no idea why my log problem in C keeps giving me 0 or -9223372036854775808 . I think it is the variable type I am using but I'm not sure 我写了这段代码,需要知道更新变量值是否存在同步问题? - I wrote this code and need to know if there is synchronization problem in updating the variable value? 我对 C 中的语法有疑问。我不太确定程序中的指针和 arrays - I have problems with the syntax in C. I'm not so sure about the pointers and the arrays in my programm 我的 C function 代码有问题 [暂停] - I'm having problem with my C function code [on hold] 我不确定为什么我在 C 中的代码会免费给我一个分段错误,有什么想法吗? - I'm not sure why my code in C is giving me a segmentation fault at free, any ideas? 使用此代码出现分段错误,但我不知道如何修复它 - Getting segmentation fault with this code but I'm not sure how to fix it 我的程序无限循环,我老实说不清楚为什么 - My program is looping infinitely, and I'm honestly not sure why 不完全确定我的回报做错了什么 - not entirely sure what I'm doing wrong with my return 我的程序有 AddressSanitizer 错误,但我不知道如何阅读 - My program has AddressSanitizer error but I'm not sure how to read it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM