Posts

Showing posts from February, 2023

Fibonacci Series (Function/Recursive) in C Programming

Recursive Function   #include <stdio.h> #include<conio.h> int fibonacci(int); void  main() {     int n, i;     printf("Enter the number of terms: ");     scanf("%d", &n);     printf("Fibonacci series: ");     for (i = 0; i < n; i++)     {         printf("%d ", fibonacci(i));     }     getch( ); } int fibonacci(int n) {     if (n <= 1)     {         return n;     }     else     {         return fibonacci(n - 1) + fibonacci(n - 2);     } } In Function #include <stdio.h> #include<conio.h> void fibonacci(int n); void main() {     int n;     printf("Enter the number of terms: ");     scanf("%d", &n);     fibonacci(n);     getch(); } void fibonacci(int n) {     int i, t1 = 0, t2 = 1, nextTerm;     printf("Fibonacci series: ");     for (i = 1; i <= n; ++i)     {         printf("%d, ", t1);         nextTerm = t1 + t2;         t1 = t2;         t2 = nextTerm;     } }

Object Oriented Programming (OOPs) (12)

Image
What is OOPs? OOP stands for Object-Oriented Programming. It is a programming paradigm that focuses on the concept of objects, which are instances of classes that contain data and methods that operate on that data. OOP is based on the idea of modularity, which means that complex systems can be built from smaller, simpler pieces that can be easily maintained and extended. In OOP, objects are the building blocks of programs, and the design and implementation of the objects are based on the principles of encapsulation, abstraction, inheritance, and polymorphism. Encapsulation is the process of hiding the implementation details of an object and providing a public interface for accessing the object's data and methods. Abstraction is the process of defining the essential features of an object and ignoring the non-essential details. Inheritance is the process of creating new classes that inherit the properties and methods of existing classes. Polymorphism is the ability of objects of diff

Practical Projects Questions (12)

WAP to input two number and display its sum using function. #include <stdio.h> #include<conio.h> int add(int , int); void main()  {     int num1, num2, sum;     printf("Enter the first number: ");     scanf("%d", &num1)     printf("Enter the second number: ");     scanf("%d", &num2);     sum = add(num1, num2);     printf("The sum of %d and %d is %d\n", num1, num2, sum);     getch(); } int add(int a, int b)  {      return a + b; }   WAP to check whether the entered number is odd or even using function #include <stdio.h> #include <conio.h> char checkEvenOdd(int); void main() {     int num;     printf("Enter an integer number: ");     scanf("%d", &num);     char result = checkEvenOdd(num);     if(result == 'E')     {         printf("%d is even.", num);     }     else     {         printf("%d is odd.", num);     }     getch(); } char checkEvenOdd(int num)