0% found this document useful (0 votes)
1 views

OOP C language

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

OOP C language

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Definition of OOP:

 Is like building with LEGOs. You create “objects” (like a car, a house,
or a person) that have their own features (color, size, doors) and
actions (driving, opening, talking). These objects work together to
make a bigger program, just like LEGOs build a bigger structure.

ADVANTAGE of OOP: *Less Mess, More Power. *Teamwork makes the


dream work. *LEGOs for code

DISADVANTAGE of OOP: *Sometimes to much structure. *Learning Curve.

HISTORY of OOP: OOP’s history goes back to the 1960s, but it really took
off in the 1980s. it was inspired by the idea of making programs more like
real-world objects.

BENEFITS of OOP: OOP keeps code tidy by grouping related data and
actions together within “objects”. You can reuse “objects” in different
programs, saving time and effort.

C language

#include <stdio.h>

Int factorial(int n) {

If (n == 0) {

Return 1;

} else {

Return n * factorial(n – 1);

Int main() {

Int number = 5;

Int result = factorial(number);

Printf(“The factorial of %d is %d\n, number, result);

Return 0;

}
 Step by Step
 Include Header File, <#include stdio.h> is a prerprocessor directive
that includews the standard input-output library in the program. This
library provides prinf and scanf for input and output operation.
 Define the Factorial Function
 The function factorial(int n) calculates the factorial of given
integer n.
 It is a recursive function that calls itself until n reaches 0.
 The base case for the recursion is when n is 0, where the
function returns 1.
 If n is not 0, the function calculates the factorial by
multiplying n with the factorial of n-1.
 Main Function
 The main() function is the entry point of the program.
 It declares an integer variable number and initializes it with
the value 5.
 It calls the factorial() function with number as an argument
and stores the result in the result variable.
 It prints the result using ptintf() function with the format
string “The factorial of %d is %d\n”.
 Compile and Run
 To run this code, you need to compile it using a C compiler like
GCC.
 After compiling, you can execute the compiled program to see
the output, which in this case will be “The factorial of 5 is
120”.

Sural, Ann Claudine D.

You might also like