Blog Moved

This website completely moved to new domain. For latest content, visit www.programmingposts.com

Search This Blog

10 Mar 2013

C PROGRAM TO FIND ROOTS OF QUADRATIC EQUATION


C PROGRAM TO FIND ROOTS OF QUADRATIC EQUATION

#include<stdio.h>
#include<math.h>
int main()
{
    float a,b,c,x,y,disc,p,q,r;
    printf("\n *** C PROGRAMS BLOG ***");
    printf("\n >>>> C PROGRAM TO FIND ROOTS OF QUADRATIC EQUATION <<<<");
    printf("\n Enter the values of a,b,c : ");
    scanf("%f %f %f",&a,&b,&c);
    disc=(b*b)-(4*a*c);
    if(disc == 0)
    {
        x=(-b)/(2*a);
        y=x;
        printf("\n Roots are Equal..");
        printf("\n x= %f , y= %f",x,y);
    }
     else if(disc < 0)
    {
        p=(-b)/(2*a);
        q=sqrt(-disc)/(2*a);
        printf("\n Roots are Complex and Imaginary..");
        printf("\n x= %f+%fi , y= %f-%fi",p,q,p,q);
    } 
     else if(disc > 0)
    {
        r=sqrt(disc);
        x=((-b)+r)/(2*a);
        y=((-b)-r)/(2*a);
        printf("\n Roots are Real Numbers..");
        printf("\n x= %f , y= %f",x,y);
    }
    else if(a==0)
    {
      x=(-c)/b;
      printf("\n Root is x = %f ",x);
    }
    getch();
    return 0;
}

Sample Output :


9 Mar 2013

C PROGRAM EXAMPLE FOR toupper() FUNCTION

C PROGRAM EXAMPLE FOR toupper() FUNCTION :


#include <stdio.h>
//#include<string.h>
int main() 
{
  int i;
  char str[20];
  printf("\n >>> C PROGRAM TO IMPLEMENT toupper() FUNCTION <<< \n");
  printf( "\n Enter the string in Lower or Mixed Case: ");
  //scanf("%s",&str); //scanf() wont allow spaces
  gets(str); //gets() allows apaces
  printf("\n The entered string in Upper Case is: ");
  for(i=0;i<=strlen(str);i++)
  {
      printf("%c",toupper(str[i]));
  }
  getch();
  return 0;
}

Output :

C PROGRAM EXAMPLE FOR tolower() FUNCTION


C PROGRAM EXAMPLE FOR tolower() FUNCTION

#include <stdio.h>
//#include<string.h>
int main() 
{
  int i;
  char str[20];
  printf("\n >>> C PROGRAM TO IMPLEMENT tolower() FUNCTION <<< \n");
  printf( "\n Enter the string in Caps or Mixed Case: ");
  //scanf("%s",&str); //wont allow spaces
  gets(str); //gets() allows apaces
  printf("\n The entered string in Lower Case is: ");
  for(i=0;i<=strlen(str);i++)
  {
      printf("%c",tolower(str[i]));
  }
  getch();
  return 0;
}

Output :