-
Notifications
You must be signed in to change notification settings - Fork 1
/
Session6.cpp
93 lines (65 loc) · 1.83 KB
/
Session6.cpp
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
#include<iostream>
using namespace std;
// Function (Method/Procedure/Routine) : A step towards modular programming
// void: return type of acknwoledgement
// calculateAreaOfCircle : name of function
// () -> No Inputs in function
// Function is created Before Main
/*void calculateAreaOfCircle(){
// Defination
float radius = 0.0, area = 0.0;
cout<<"Enter Radius of Circle: \n";
cin>>radius;
area = 3.14 * radius * radius;
cout<<"Area of Circle with radius "<<radius<<" is "<<area<<"\n";
}*/
// Function with Inputs
/*void addNumbers(int num1, int num2){
int num3 = num1 + num2;
cout<<"Sum of "<<num1<<" and "<<num2<<" is: "<<num3;
}*/
// Declaring a Function before using it in main !!
void calculateAreaOfCircle();
void addNumbers(int num1, int num2);
// Function with Inputs and with Acknowledgement (Return Type)
// Return is always 1
// Inputs can be many
int sqaureOfNumber(int num){
int result = num * num;
return result;
}
int main(){
int age = 10;
cout<<"age is: "<<age<<"\n";
// Execution of Function or Calling a Function
//calculateAreaOfCircle();
//calculateAreaOfCircle();
addNumbers(10,20);
addNumbers(30,40);
int res = sqaureOfNumber(5);
cout<<"Result is: "<<res<<"\n";
return 0;
}
// Function with Inputs
void addNumbers(int num1, int num2){
int num3 = num1 + num2;
cout<<"Sum of "<<num1<<" and "<<num2<<" is: "<<num3<<"\n";
}
// Function is created After Main
void calculateAreaOfCircle(){
// Defination
float radius = 0.0, area = 0.0;
cout<<"Enter Radius of Circle: \n";
cin>>radius;
area = 3.14 * radius * radius;
cout<<"Area of Circle with radius "<<radius<<" is "<<area<<"\n";
}
/*
PS:
header files -> contains declarrations of varous functions which we wil luse in our program
defination of function is available in a library which we install in our system
MyProg.cpp
Compiler
MyProg.obj
Linker
*/