-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.c
More file actions
150 lines (128 loc) · 3.22 KB
/
Copy pathfunction.c
File metadata and controls
150 lines (128 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include<stdio.h>
void printHello(); // function Declaration
int main(){
printHello(); // function call
printHello();
printHello();
return 0;
}
void printHello(){ // function definination
printf("Hello! \n");
}
// Write 2 functions - one to print Hello and second to print Good bye.--------------------------------------------
#include<stdio.h>
void printHello();
void printgoodbye();
int main(){
printHello(); // function call
printgoodbye();
return 0;
}
void printHello(){
printf("Hello \n");
}
void printgoodbye(){
printf("good bye\n");
}
// Write a function that prints Namaste if user is indian anmd Bonjour if user is french.-----------------------------
#include<stdio.h>
void namaste();
void bonjour();
int main(){
char ch;
printf("Enter i for indian & f for french : ");
scanf("%c", & ch);
if (ch == 'i'){
namaste();
}else{
bonjour();
}
return 0;
}
void namaste(){
printf("Namaste");
}
void bonjour(){
printf("Bonjour");
}
// table print using function --------------------------------------------------------------------------------------------------
#include<stdio.h>
void printtable(int n);
int main (){
int n;
printf("enter number : ");
scanf("%d",& n);
printtable(n); // argument / actual parameter
return 0;
}
void printtable(int n){ // parameter/formal parameter
for (int i = 1; i <=10; i++){
printf("%d \n",i*n);
}
}
// sum print using function --------------------------------------------------------------------------------------------------
#include<stdio.h>
int sum(int a, int b);
int main (){
int a, b;
printf("enter first number : ");
scanf("%d",& a);
printf("enter second number : ");
scanf("%d",& b);
int s = sum(a,b);
printf("sum is : %d",s);
return 0;
}
int sum(int a, int b){
return a+b;
}
// Use library functions to calculate the sqare the of a number given by user.------------------------------------------------------
#include<stdio.h>
#include<math.h>
int main (){
int n = 4;
printf("%f",pow(n,2));
return 0;
}
// Write functions to calucalte area of sqare, a circle & a rectangle.------------------------------------------
#include<stdio.h>
#include<math.h>
float sqareArea(float side);
float circleArea(float rad);
float rectangleArea(float a, float b);
int main (){
float a = 5.0;
float b = 10.0;
float rad = 6.0;
float side = 7.0;
printf("Rectanlge area is : %f \n", rectangleArea(a,b));
printf("Sqare area is : %f \n", sqareArea(side * side ));
printf("circle area is : %f\n", circleArea( 3.14 * rad * rad));
return 0;
}
float sqareArea(float side){
return side * side ;
}
float circleArea(float rad){
return 3.14 * rad * rad;
}
float rectangleArea(float a, float b){
return a*b;
}
// find the max number.-------------------------------------------------
#include <stdio.h>
int max(int x, int y){
return (x>y)? x:y;
}
int max_of_four(int a, int b, int c, int d){
int max1 = max(a ,b);
int max2 = max(c ,d);
return max(max1, max2);
}
int main() {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
int ans = max_of_four(a, b, c, d);
printf("%d", ans);
return 0;
}