Thursday, October 30, 2025

Enter Coefficient of Quadratic Equations. Find the Properties of Equation.

#include<stdio.h>
#include<math.h>
main()
{
   float a,b,c;
   float d,r1,r2;
   /* 1 3 8        0 5 8       2 4 2     3 8 2 */
   printf("\n Enter the Values of A B C: ") ;
   scanf("%f%f%f", &a,&b,&c) ;
   d = b * b - 4 * a * c;
   if(a != 0)
   {
      if(d < 0)
      {
         r1=-b/(2*a);
         r2= sqrt(-d)/(2*a);
    printf("\n Roots are Complex/Imaginary.\n");
         printf("\n Root1 = %.3f%+.3fi",r1,r2);
         printf("\n Root2 = %.3f%+.3fi",r1,-r2);
      }
      else
      if(d==0)
      {
    printf("\n Both Roots are Real and Equal.\n");
    r1 = -b /(2* a);
    printf("\n Root1 = %.3f ",r1);
         printf("\n Root2 = %.3f ",r1);
      }
      else
      if(d > 0)
      {
    printf("\n Roots are Real  and Unequal.\n");
    r1 = ( -b + sqrt(d)) / (2* a);
    r2 = ( -b - sqrt(d)) / (2* a);
    printf("\n Root1 = %.3f , Root2 = %.3f",r1,r2);
      }
    }
    else
       printf("\n Equation is linear.");
}





Input 3 values. To find Triangle is Possible or Not. If Triangle is Possible then Find Nature of Triangle.

 


#include<stdio.h>
main()
{
    int a,b,c;
    printf("\n\nEneter 3 Values : ");
    scanf("%d%d%d",&a,&b,&c);
    if((a+b>=c) && (b+c>=a) && (c+a>=b))
    {
       printf("\nTriangle is Possible");
       if(a==b && b==c && c==a)
   printf("\nEquilateral Triangle");
       else
       if(a==b || b==c || c==a)
           printf("\nIsosceles Triangle");
       else
           printf("\nScalene Triangle");
     }
     else
          printf("\nTriangle is Not Possible"); 
}




Input Roll No, Student Name & 3 Subject Marks. To calculate Total, Avg. & Find Result is 'Pass' or 'Fail'



#include<stdio.h>
main()
{
     int rno,m1,m2,m3,tot=0;
     float avg=0.0;
     char sn[20];
     printf("\nEnter RNo. SName & 3 Subject Marks. ");
     scanf("%d%s%d%d%d",&rno,sn,&m1,&m2,&m3);
     tot=m1+m2+m3;
     avg=tot/3.0;
     printf("\nRoll No. %d\nSt. Name  %s\nTotal %d\Average %.2f",rno,sn,tot,avg);
     if(m1>=35 && m2>=35 && m3>=35)
          printf("\nResult is Pass");
    else
          printf("\nResult is Fail");
}





Find Biggest of given Two Numbers and Find Biggest of given Three Numbers.

Find Biggest of given Two Numbers


#include<stdio.h>
main()
{
    int a,b;
    printf("\nEnter A and B values");
    scanf("%d%d",&a,&b);
    if(a>b)
       printf("\nA is Big");
    else
       printf("\nB is Big");
}

        




Find Biggest of given Three Numbers.

#include<stdio.h>
main()
{
    int a,b,c;
    printf("\nEnter A,B and C values");
    scanf("%d%d%d",&a,&b,&c);
    if(a>b && a>c)
       printf("\nA is Big");
    else
    if(b>c)
       printf("\nB is Big");
    else
       printf("\nC is Big");
}

         

    (or)


#include<stdio.h>
main()
{
     int a,b,c;
     printf("\nEnter A B &  C Values : ");
     scanf("%d%d%d",&a,&b,&c);
     if(a>b)
          if(a>c)
             printf("\nA is Big  %d",a);
          else
             printf("\nC is Big  %d",c);  
     else
     if(b>c)
        printf("\nB is Big  %d",b);   
     else
        printf("\nC is Big  %d",c);
}






Wednesday, October 29, 2025

Decision Making in C (if - else)

 

Decision Making in C (if - else)

 

 

The if statement is powerful decision making statement in C. It is used to control the flow of execution of execution.

Types of if Statements in C

  1.   Simple if Statement
  2.   if...else  Statement
  3.   Nested if...else  Statement
  4.   if-else-if Ladder

 

Simple if Statements

The syntax of a Simple if Statement is

       if(condition)

            statement1;

       statements; 

  if condition is true then executed statement1 and followed statements. if condition is false executed statements.

 

The statement-block.

       if(condition)

      {  

            statement1;

            statement2;

            ---------

            statement n;

      }

      statements;

 

if condition is true then executed Block statements and followed statements. if condition is false executed statements.

 

if...else  Statement

 

        if(condition)

       {

            statement 1;

            statement 2;

            ----------

            statement n;

       } 

       else

       {

            statement 1;

            statement 2;

            ----------

            statement n;

       } 

       statements;

 

if condition is true then executed true Block statements and followed statements. if condition is false then executed false block statements and followed statements.

 

Nested if...else  Statement

Nested Condition: Condition in Condition is called Nested Condition.

 

         if(condition)
            if(condition)
               statement 1;
            else
               statement 2;
          else

            statement 3;

 

if condition is true then executed next if condition and it is true then excited statement1. if second if false  and executed statmenet2.if condition is false executed statements3.

 

if-else-if Ladder

 

The if-else-if Ladder is multipath decision.

   if(condition1)

      statement 1;

  else if(condition2)

      statement 2;

  else if(condition3)

      statement 3;

  -------

  else if(condition n)

      statement n;

 

 

Wednesday, October 22, 2025

Mathematical Functions in C

 Mathematical Functions in C


C programming provides a rich set of mathematical functions, primarily found within the <math.h> header file. To utilize these functions, this header file must be included at the beginning of the C source code.


Math Functions 


ceil(x) Get smallest integral value that exceeds x. 

floor(x) Get largest integral value less than x. 

fmod(x,y) Divide x by y with integral quotient and return remainder. 

abs(n) Find absolute value of integer n. 

fabs(x) Compute absolute value of x. 

log(x) Compute log(x). 

log10(x) Compute log to the base 10 of x. 

exp(x)  Compute exponential of x 

pow(x, y)    Compute x raised to the power y. 

sqrt( x)    Compute the square root of x. 


 Trigonometric Functions 

sin(x) Compute sine of angle in radians. 

cos(x) Compute cosine of angle in radians. 

tan( x) Compute tangent of angle in radians. 

acos(x) Compute arc cosine of x. 

asin(x)  Compute arc sine of x. 

atan(x) Compute arc tangent of x. 

atan2(y,x) Compute arc tangent of y/x, using the signs of both arguments to determine  the quadrant of the return value. 



Hyperbolic Functions 

sinh(x) Compute the hyperbolic sine of x. 

cosh(x) Compute the hyperbolic cosine of x. 

tanh( x) Compute the hyperbolic tangent of x. 


C Example Program for math functions

#include<stdio.h>

main()

{

    printf("\n           Maths Functions");

    printf("\n           ***************");

    printf("\nCeil(2.546)             = %f",ceil(2.546));

    printf("\nFloor(2.546)            = %f",floor(2.546));

    printf("\nFMod(5.0/2.0)           = %f",fmod(5.0,2.0));

    printf("\nAbs(-5)                 = %f",abs(-5));

    printf("\nFAbs(-5.0)              = %f",fabs(-5.0));

    printf("\nLog(1.234)              = %f",log(1.234));

    printf("\nLog10(1.234)            = %f",log10(1.234));

    printf("\nExp(1.234)              = %f",exp(1.234));

    printf("\nPow(5,3)                = %f",pow(5,3));

    printf("\nSqrt(9)                 = %f",sqrt(9));


    printf("\n         Trigonometric Functions");

    printf("\n         ***********************");

    printf("\nSine(90)                = %f",sin(90*3.14/180));

    printf("\nCosine(90)              = %f",cos(90*3.14/180));

    printf("\nTangent(90)             = %f",tan(45*3.14/180));


    printf("\nArc Sine(0.7)           = %f",asin(0.7));

    printf("\nArc Cosine(0.7)         = %f",acos(0.7));

    printf("\nArc Tangent(0.7)        = %f",atan(0.7));

    printf("\nArc Tangent(0.7/2.0)    = %f",atan2(0.7,2.0));


    printf("\n           Hyperbolic Functions");

    printf("\n           ********************");

    printf("\nHyperbolic Sine(0.7)    = %f",sinh(0.7));

    printf("\nHyperbolic Cosine(0.7)  = %f",cosh(0.7));

    printf("\nHyperbolic Tangent(0.7) = %f",tanh(0.7));

}



Operator Precedence and Associativity in C

Operator Precedence and Associativity in C



Each operator in C has a precedence associated with it. The precedence of operators determines the order in which they are evaluated in an expression. Operators with higher precedence are evaluated first.


                  

 Operator   

Description

   Associativity   

Precedence   

( )

Function call

Left-to-Right

1

[ ]

Array element reference

 

+

Unary plus

Right-to-Left

2

-

Unary minus

++

Increment

--

Decrement

!

Logical negation

~

Ones complement

*

Pointer reference (indirection)

&

Address

sizeof

Size of an object

(type)

Type cast(conversion)

 

*

Multiplication

Left-to-Right

3

/

Division

%

Modulus

 

+

Addition

Left-to-Right

4

-

Subtraction

 

<< 

Left Shift

Left-to-Right

5

>> 

Right shift

 

< 

Less than

Left-to-Right

6

<=

Less than or equal to

?

Greater than

>=

greater than or equal to

 

==

Equality

Left-to-Right

7

!=

Inequality

 

&

Bitwise AND

Left-to-Right

8

 

^

Bitwise XOR

Left-to-Right

9

 

|

Bitwise OR

Left-to-Right

10

 

&&

Logical AND

Left-to-Right

11

 

||

Logical OR

Left-to-Right

12

 

?:

Conditional expression

Right-to-Left

13

 

=

Assignments  operators

Right-to-Left

14

*=  /=  %=

+= -=  &=

^=  |=

<<=  ??=\

 

,

Comma operator

Left-to-Right

15