|
CS256 - Principles of Structured Design
Fall 2021
|
Displaying ./code/sternflCode/nov2.c
#include<stdio.h>
//expects an integer value to be plugged in
//function f will return an integer value
int f(int x); //prototype or function declaration
int g(int x, int *p);
int main() {
// comunicates to the function by plugging 137
printf("%d\n", f(137));
//function communicates back to main by returning a value
//-------------------
int num = 34;
//main and function g communicate
int x;
printf("Please enter a non-zero value ");
scanf("%d", &x);
if (0==g(x,&num))
printf("%d\n", num);
else
printf("can NOT divide by 0\n");
}
//function definition
int f(int x) {
return 3*x;
}
int g(int x, int *p) {
if (x==0) return 1;
*p = (*p)/x;
return 0;
}
|