Posts

Showing posts from November, 2023

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 d...

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 ; }

Addition Example for Run Time value (Using scanf)

  #include <stdio.h> int main () {     double num1, num2;     printf ( "Enter the first number: " );     scanf ( " %lf " , & num1);     printf ( "Enter the second number: " );     scanf ( " %lf " , & num2);     double sum = num1 + num2;     printf ( "Sum of %.2lf and %.2lf is %.2lf \n " , num1, num2, sum);     return 0 ; }

scanf() Example

  #include <stdio.h> int main () {     int integerInput ;     float floatInput ;     char characterInput [ 50 ];     printf ( "Enter an integer: " );     scanf ( " %d " , & integerInput );     printf ( "Enter a floating-point number: " );     scanf ( " %f " , & floatInput );     printf ( "Enter a character or a word: " );     scanf ( " %s " , characterInput );     printf ( " \n You entered: \n " );     printf ( "Integer: %d \n " , integerInput );     printf ( "Float: %f \n " , floatInput );     printf ( "Character/Word: %s \n " , characterInput );     return 0 ; }

Global and Local Variable Program

  #include <stdio.h> // Global variable declaration int globalVar = 10 ; // Function that uses a global variable void functionWithGlobalVariable () {     printf ( "Inside functionWithGlobalVariable: \n " );     printf ( "Global variable globalVar: %d \n " , globalVar ); } // Function that uses local variables void functionWithLocalVariables () {     int localVar = 20 ; // Local variable declaration     printf ( " \n Inside functionWithLocalVariables: \n " );     printf ( "Local variable localVar: %d \n " , localVar );     // Accessing the global variable from within a function     printf ( "Global variable globalVar: %d \n " , globalVar ); } int main () {     // Accessing the global variable from the main function     printf ( "Inside main: \n " );     printf ( "Global variable globalVar: %d \n " , globalVar );     functionWithGlobalVariable ();   ...

Addition Subtraction Multiplication and Division Example

#include <stdio.h> int main () {     double num1, num2;         printf ( "Enter the first number: " );     scanf ( " %lf " , & num1);         printf ( "Enter the second number: " );     scanf ( " %lf " , & num2);         // Addition     printf ( " %.2lf + %.2lf = %.2lf \n " , num1, num2, num1 + num2);         // Subtraction     printf ( " %.2lf - %.2lf = %.2lf \n " , num1, num2, num1 - num2);         // Multiplication     printf ( " %.2lf * %.2lf = %.2lf \n " , num1, num2, num1 * num2);         // Division     if (num2 != 0 ) {         printf ( " %.2lf / %.2lf = %.2lf \n " , num1, num2, num1 / num2);     } else {         printf ( "Division by zero is not allowed. \n " );     }         retur...

Moods of Verbs

  Definition:   You learned earlier in this module that the   tense   of a verb indicates   when   an action occurred, but each verb also has a   mood   that tells us   how   the action is viewed or perceived by the speaker. It indicates whether something is a fact, opinion, command, suggestion, request, wish, hypothetical (imaginary) situation, or uncertainty. Moods are as important in writing as they are in our lives because they provide perspective. In English the three primary moods are indicative, imperative, and subjunctive. Indicative Mood Indicative mood  is fact mood, and it's the one we use most often. It states, asks, or denies a fact. However, it can also express an opinion because opinions are often stated as facts; when you have an opinion about something, you usually view it as a fact. Almost all the verbs you've studied so far have been in the indicative mood, so you're already familiar with it. The simple, progressi...

The Verb To Be

  In this lesson you'll learn that   to be   is used as either a   linking   or   helping   verb. Since   to be   is an irregular verb, let's do a quick review of its forms before diving into the material. To Be : Present and Past Tenses Person and Number Present Past First person singular ( I ) am was First person plural ( we ) are were Second person singular or plural ( you ) are were Third person singular ( he ,  she ,  it ) is was Third person plural ( they ) are were To Be : Present and Past Participles Present Past being been To Be  As a Linking Verb To be  is considered a  linking verb  when it's used to describe traits, characteristics, emotions, and states of being. It connects the main noun (or  subject ) to a describing word, such as an  adjective  or another  noun . Traits and Characteristics Daphne  is  very  kind . Is  links the noun  Daphne  and the...