Posts

Showing posts from May, 2025

Simple Interest Calculator in C

Simple Interest Calculator in C Introduction Calculating simple interest is a common financial computation. This program takes principal, rate, and time as inputs to compute interest. Program # include <stdio.h> int main () { float principal, rate, time, interest; printf ( "Enter principal amount: " ); scanf ( "%f" , &principl); printf ( "Enter rate of interest: " ); scanf ( "%f" , &rate); printf ( "Enter time (in years): " ); scanf ( "%f" , &time); interest = (principl * rate * time) / 100 ; printf ( "Simple Interest = %.2f" , interest); return 0 ; } Explanation (principal * rate * time) / 100 : Formula to calculate simple interest. %.2f : Formats the output to two decimal places.

Even or Odd Checker in C Language

 Even or Odd Checker in C Language Introduction Determining whether a number is even or odd is a basic programming exercise. This program uses the modulus operator to check. Program # include <stdio.h> int main () { int num; printf ( "Enter an integer: " ); scanf ( "%d" , &num); if (num % 2 == 0 ) printf ( "%d is even." , num); else printf ( "%d is odd." , num); return 0 ; } Explanation num % 2 == 0 : Checks if the number is divisible by 2. If true, the number is even; otherwise, it's odd.

Swapping Two Numbers in C Language

 Swapping Two Numbers in C Language Introduction Swapping values of two variables is a common task. This program demonstrates swapping using a temporary variable. # include <stdio.h> int main () { int a, b, temp; printf ( "Enter two integers: " ); scanf ( "%d %d" , &a, &b); temp = a; a = b; b = temp; printf ( "After swapping: a = %d, b = %d" , a, b); return 0 ; } Explanation temp = a; : Stores the value of a in temp . a = b; : Assigns the value of b to a . b = temp; : Assigns the original value of a to b .

Sum of Two Numbers in C Language

 Sum of Two Numbers in C Introduction: Adding two numbers is a fundamental operation in programming. This program demonstrates how to take user input and perform addition. Program: # include <stdio.h> int main () { int num1, num2, sum; printf ( "Enter two integers: " ); scanf ( "%d %d" , &num1, &num2); sum = num1 + num2; printf ( "Sum: %d" , sum); return 0 ; } Explanation: int num1, num2, sum; : declared num1,num2 and sum as integer. scanf("%d %d", &num1, &num2); : Reads two integers from the user and stores in num1 and num2 integers. sum = num1 + num2; : Calculates the sum of the two numbers. printf("Sum: %d", sum); : Used to displays the result in output screen.