用2个函数计算

标签 c function int

我是函数的初学者。我想将该函数集成到我的主程序中。程序应该扫描一个 int 数字,然后对其进行平方(sum=b*b)。然后程序应该输出结果。

#include <stdio.h>
#include <stdlib.h>
void funktion(int);
void out(int);
int main(int)
{
int sum,b,v,w,z;
{
    funktion();
    calculator();
    out();
    printf("%i",sum);
}
return 0;
}

void funktion(int v)
{
printf("Enter any number that is to be squared!");
}
void calculator(int w) //calculate b*b
{
scanf("%i",&b);
sum=b*b;
}
void out(int z)
{
printf("Sum:");
}

请给我一些建议。 ;) 谢谢并致以最诚挚的问候!

最佳答案

您是否正在寻找这种解决方案:我只是做了一些小小的改变。如果您要使用此代码,您可能需要执行一些初始化操作

#include <stdio.h>
#include <stdlib.h>
void funktion(int);
void out(int);
int main()
{
int sum,b;
{
    printf("Enter any number that is to be squared!");  
    scanf("%i",&b);

    sum = funktion(b);
    out(sum);
}
return 0;
}

int funktion(int b)
{
    return b*b;
}
void out(int sum)
{
    printf("Sum:%d",sum);
}

关于用2个函数计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22830337/

相关文章:

c - 指针解引用数组

function - 忽略 sapply 函数中的 NA

c# - 指定的转换对字段 int 无效

C - K&R 练习 2.4 - 为什么我会收到总线错误?

c - c程序中bash sleep和sleep的区别

c - _setmode 函数导致调试错误

python - 覆盖内部函数

r - 在 R 中创建一个函数来搜索并删除给定 NA 的数据

java - 在Java中根据种子创建一个随机整数数组

c++ - 从 double* 转换为 int 会失去精度