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 CHECK WHETHER GIVEN YEAR IS LEAP YEAR OR NOT


C PROGRAM TO CHECK WHETHER GIVEN YEAR IS LEAP YEAR OR NOT

#include<stdio.h>
void LeapYear(int);
void main()
{
    int year;
    printf("\n *** C PROGRAMS BLOG *** \n");
    printf("\n >>>> C PROGRAM TO CHECK WHETHER GIVEN YEAR LEAP YEAR OR NOT <<<< \n");
    printf("\n Enter the year : ");
    scanf("%d",&year);
    LeapYear(year);
    getch();
    return 0;
}
void LeapYear(int yr)
{
    int rem1,rem2;
    rem1 = yr%4 ; //rem1 = 0 for leap year
    rem2 = yr%100; //rem2! = 0 for leap year
    if((rem1 == 0) && (rem2!=0) || yr%400 == 0)
    {
        printf("\n The given year %d is Leap Year..",yr);
    }
    else
    {
        printf("\n The given year %d is Not Leap Year..",yr);
    }
    
}

Sample Output :



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 :

C PROGRAM TO PERFORM ARITHMETIC OPERATIONS USING SWITCH LOOP


C PROGRAM TO PERFORM ARITHMETIC OPERATIONS USING SWITCH LOOP :

#include<stdio.h>
void main()
{
    float value1,value2;
    char operator;
    printf("\n >>> PROGRAM TO PERFORM ARITHMETIC OPERATIONS USING SWITCH LOOP <<< \n");
    printf("\n Enter Your Expression : ");
    scanf("%f %c %f",&value1,&operator,&value2);
    switch(operator)
    {
        case '+' : printf("\n Addition Result  is :  %f \n",value1+value2);
            break;
        case '-' : printf("\n Subtraction Result  is : %f \n",value1-value2);
            break;
        case '*' : printf("\n Multiplication Result  is : %f \n",value1*value2);
            break;
        case '/' : printf("\n Division Result is : %f \n",value1/value2);
            break;
        default : printf("\n Unknown operator");
            break;
    }
    getch();
}

Output :


visit :  C Program to Show the Operations of Arithmetic Operators