Posts

Simple Interest Calculation

#include <stdio.h> int main () {     double principal , rate , time , simpleInterest ;     // Input principal amount, rate, and time     printf ( "Enter the principal amount: " );     scanf ( " %lf " , & principal );     printf ( "Enter the rate of interest (in percentage): " );     scanf ( " %lf " , & rate );     printf ( "Enter the time (in years): " );     scanf ( " %lf " , & time );     // Calculate simple interest     simpleInterest = ( principal * rate * time ) / 100 ;     // Display the calculated simple interest     printf ( "Simple Interest: %.2lf \n " , simpleInterest );     return 0 ; }

Find a Remaining Day

  #include <stdio.h> #include <time.h> int main () {     struct tm userDate ;     time_t currentTime , userTime ;     double secondsRemaining , daysRemaining ;     // Get the current time     time ( & currentTime );     // Prompt the user to enter a date     printf ( "Enter a date (YYYY-MM-DD): " );     scanf ( " %d - %d - %d " , & userDate . tm_year , & userDate . tm_mon , & userDate . tm_mday );     // Adjust the year and month values     userDate . tm_year -= 1900 ; // Years since 1900     userDate . tm_mon -= 1 ;     // Month (0-11)     // Convert the user-specified date to a time_t value     userTime = mktime ( & userDate );     // Calculate the remaining time in seconds     secondsRemaining = difftime ( userTime , currentTime );     // Calculate the remaining days     daysRemaining = secondsRemaining / ( 60 * 60 * 24 );     if ( daysRemaining < 0 ) {         printf ( "The specified date is in

Find the Volume of Cube

#include <stdio.h> int main () {     double side , volume ;     printf ( "Enter the length of one side of the cube: " );     scanf ( " %lf " , & side );     if ( side >= 0 ) {         volume = side * side * side ; // Calculate the volume of the cube         printf ( "The volume of the cube with side length %.2lf is %.2lf \n " , side , volume );     } else {         printf ( "Invalid side length. Please enter a non-negative value. \n " );     }     return 0 ; }  

Area of Circle

  #include <stdio.h> #include <math.h> int main () {     double radius , area ;     printf ( "Enter the radius of the circle: " );     scanf ( " %lf " , & radius );     if ( radius >= 0 ) {         area = M_PI * radius * radius ; // M_PI is a constant for the value of π         printf ( "The area of the circle with radius %.2lf is %.2lf \n " , radius , area );     } else {         printf ( "Invalid radius. Please enter a non-negative value. \n " );     }     return 0 ; }

Find Gross Salary Example

  #include <stdio.h> int main () {     double basicSalary , allowances , deductions , grossSalary ;     // Input the basic salary, allowances, and deductions     printf ( "Enter the basic salary: " );     scanf ( " %lf " , & basicSalary );     printf ( "Enter the total allowances: " );     scanf ( " %lf " , & allowances );     printf ( "Enter the total deductions: " );     scanf ( " %lf " , & deductions );     // Calculate the gross salary     grossSalary = basicSalary + allowances - deductions ;     // Display the gross salary     printf ( "Gross Salary: %.2lf \n " , grossSalary );     return 0 ; }

Find Square root of Number

  #include <stdio.h> #include <math.h> int main () {     double num , squareRoot ;     printf ( "Enter a number: " );     scanf ( " %lf " , & num );     if ( num >= 0 ) {         squareRoot = sqrt ( num );         printf ( "Square root of %.2lf is %.2lf \n " , num , squareRoot );     } else {         printf ( "Cannot compute the square root of a negative number. \n " );     }     return 0 ; }

Subtract two numbers without using subtraction (-) Operator

  #include <stdio.h> int main () {     int num1 , num2 , result ;     printf ( "Enter the first number: " );     scanf ( " %d " , & num1 );     printf ( "Enter the second number: " );     scanf ( " %d " , & num2 );     // Subtract num2 from num1 without using the '-' operator     result = num1 + ( - num2 );     printf ( "The result of %d - %d is %d \n " , num1 , num2 , result );     return 0 ; }