小编use*_*330的帖子

为什么我不能在这个程序中构建一个无返回类型的函数?

这是一个使用函数乘以和添加两个数字的小程序.

#include<conio.h>
#include<stdio.h>

int main()

{
 int a,b,result;
 clrscr();
 printf("Enter two numbers to be added and multiplied...\n");
 scanf("%d%d",&a,&b);
add(a,b);
 getch();
 return 0;
}

int add(int a,int b)
{
int res;
 printf("%d + %d = %d", a,b,a+b);
 res=mult(a,b);
 printf("\n%d * %d = %d",a,b,res);
 return 0;
}

int mult(int a,int b)
{
 return a*b;
}
Run Code Online (Sandbox Code Playgroud)

虽然,我不认为我需要有一个返回类型添加功能,所以我试着使用这个代码...

#include<conio.h>
#include<stdio.h>

int main()

{
 int a,b,result;
 clrscr();
 printf("Enter two numbers to be added and multiplied...\n");
 scanf("%d%d",&a,&b);
add(a,b);
 getch();
 return 0;
}

void add(int a,int b) …
Run Code Online (Sandbox Code Playgroud)

c return function void

1
推荐指数
1
解决办法
70
查看次数

为什么我无法在C中为我的结构创建新节点?(使用Netbeans)

#include<stdio.h>
#include<stdlib.h>

struct node{
 int info;
 node *link;
 };

 node *top = NULL;
 void push();
 void pop();
 void display();

 main()
 {
  int choice;

  while(1)
  {
  printf("Enter your choice:\n1.Push\n2.Pop\n3.Display\n4.Exit\n");
  scanf("%d",&choice);

  switch(choice)
  {
   case 1:
    push();
    break;
   case 2:
    pop();
    break;
   case 3:
    display();
    break;
   case 4:
    exit(1);
    break;
   default:
    printf("Wrong choice");
   }
//   getch();
  }
 }

 void push()
 {
  node *tmp;
  int pushed_item;
  tmp = new node;
  printf("Enter the value to be pushed in the stack:");
  scanf("%d",&pushed_item);
  tmp->info=pushed_item;
  tmp->link=top;
  top=tmp;
 } …
Run Code Online (Sandbox Code Playgroud)

c stack struct pointers netbeans

0
推荐指数
1
解决办法
84
查看次数

标签 统计

c ×2

function ×1

netbeans ×1

pointers ×1

return ×1

stack ×1

struct ×1

void ×1