[英]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
包含两个语句:
Num
as a function without return value.将Num
本地(重新)声明为没有返回值的函数。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.