Skip to main content

Featured

C++ Program to Find Fibonacci Number

  C++ Program to Find Fibonacci Number ✅ C++ Program to Find Fibonacci Number (Iterative Method) πŸ“‹ Copy Code #include <iostream> using namespace std; int fib(int n) { if (n == 0) return 0; if (n == 1) return 1; int a = 0, b = 1, c; for (int i = 2; i <= n; i++) { c = a + b; a = b; b = c; } return b; } int main() { int n; cout << "Enter a number: "; cin >> n; cout << "Fibonacci number = " << fib(n); return 0; } πŸ“˜ Explanation: This C++ program calculates the Fibonacci number for a given input using the iterative approach . The Fibonacci sequence starts as: 0, 1, 1, 2, 3, 5, 8, ... Each number is the sum of the previous two numbers. This program avoids recursion and uses a loop, which makes it more efficient in terms of time and memory. 🧾 Sample Output: Enter ...

C Program to Check Leap Year

C Program to Check Leap Year

✅ C Program to Check Leap Year


#include <stdio.h>

int main()
{
    int year;

    printf("Enter a year: ");
    scanf("%d", &year);

    if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
        printf("%d is a Leap Year\n", year);
    else
        printf("%d is NOT a Leap Year\n", year);

    return 0;
}
  

πŸ“˜ Explanation:

This C program checks whether a given year is a leap year or not.

A year is a leap year if:

  • It is divisible by 400, OR
  • It is divisible by 4 but not divisible by 100

These conditions are checked using logical operators and modulus (%) operator.

🧾 Sample Output:

Enter a year:
2024
2024 is a Leap Year
  

πŸ”‘ Keywords:

C leap year program, leap year logic in C, C conditional statements, C if else program, year checking in C

πŸ” Search Description:

Learn how to check whether a given year is a leap year in C programming with simple logic, explanation, and output.

πŸ“Œ Hashtags:

#CProgramming #LeapYear #CPrograms #ProgrammingBasics #1printf

Comments

Popular Posts

πŸŒ™