Posts

Showing posts from December, 2025

2️⃣C Program to check Prime Number(With Program and Explanation)

  C Program to Check Prime Number 🔹 Introduction A prime number is a natural number greater than 1 that has exactly two distinct positive divisors: 1 and itself. In this post, we will write a C program to check whether a given number is prime or not. This program is useful for beginners to understand loops, conditions, and basic number logic in C. 🔹 Problem Statement Write a C program to check whether a given number is a prime number or not. 🔹 Algorithm Start Read an integer n If n ≤ 1 , it is not prime Check divisibility from 2 to n/2 If divisible, number is not prime Otherwise, number is prime Stop 🔹 Source Code (C Program) # include < stdio.h > int main () { int n, i, flag = 0 ; printf ( "Enter a number: " ); scanf ( "%d" , &n); if (n <= 1 ) { flag = 1 ; } for (i = 2 ; i <= n / 2 ; i++) { if (n % i == 0 ) { flag = 1 ; break ; ...

1️⃣Fibonacci Series in C (With Program and Explanation)

Fibonacci Series in C (With Program and Explanation) Introduction In this blog post, we will learn about the Fibonacci series and how to write a C program to print the Fibonacci series. This topic is very important for beginners , college exams , and coding interviews . What is Fibonacci Series? The Fibonacci series is a sequence of numbers in which: The first two numbers are 0 and 1 Each next number is the sum of the previous two numbers Example: 0, 1, 1, 2, 3, 5, 8, 13, 21, ... Formula: Fn = F(n- 1 ) + F(n- 2 ) Fibonacci Series Program in C C Program to Print Fibonacci Series # include <stdio.h> int main () { int n, first = 0 , second = 1 , next, i; printf ( "Enter the number of terms: " ); scanf ( "%d" , &n); printf ( "Fibonacci Series: " ); for (i = 1 ; i <= n; i++) { printf ( "%d " , first); next = first + second; first = second; second = next; ...