这是一个使用函数乘以和添加两个数字的小程序.
#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) #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)