Search Your C Program

Monday, 30 January 2012

Program to perform basic arithmatic operation using switch statement

#include<stdio.h>
#include,conio.h>
void main()

                 int a,b,c,choice;
                 clrscr();
                 printf("\n Enter two numbers");
                 scanf(" %d %d ", &a, &b);
                 printf("\n Press 1 for Addition ");
                 printf("\n Press 2 for Subtraction ");
                 printf("\n Press 3 for Multiplication ");
                 printf("\n Press 4 for Division ");
                 printf("\n Enter your choice");
                 scanf(" %d", &choice);
                 switch(choice)
                 {
                                       case 1:
                                       c=a+b;
                                       printf("\n Sum = %d",c);
                                       break;
                                      
                                       case 2:
                                       c=a-b;
                                       printf("\n Subtraction = %d",c);
                                       break;

                                       case 3:
                                       c=a*b;
                                       printf("\n Multiplication = %d",c);
                                       break;

                                       case 4:
                                       c=a/b;
                                       printf("\n Division = %d",c);
                                       break;
                
                                       default :
                                       printf("\n Wrong Input");
                }
                getch();

 
                   

Program to find whether a year is leap or not using conditional operators.

#include<stdio.h>
#include<conio.h>
void  main()

                  int year;
                  clrscr();
                  printf("\n Enter  the year");
                  scanf("%d",&year);
                  (( year % 100 ==0 && year % 400 == 0) || (year % 100 !=0 &&  year % 4 == 0))?
                  printf("\n Year  %d  is leap ",year):printf("\n Year  %d  is  not leap ",year);
                  getch();
}

Program to find Greater from three using conditional operators

#include<stdio.h>
#include<conio.h>
void main()
{
                  int a,b,c,big;
                  clrscr();
                  printf("\n Enter three numbers ");
                  scanf(" % d  %d  %d ",&a,&b,&c);
                  big=a>b?(a>c?a:c):(b>c?b:c);
                  printf("\n Biggest Number = %d",big);
                  getch();
}
                

Sunday, 29 January 2012

Program to determine whether a year is leap or not.

#include<stdio.h>
#include<conio.h>
void main()
{
                 int year;
                 clrscr();
                 printf("\n Enter the year");
                 scanf("%d",&year);
                 if (year%100==0)
                 {
                                           if(year%400==0)
                                                     printf("\n Year %d  is leap",year);
                                           else
                                                     printf("\n Year %d is not leap", year);


                 }
              
                 else
                 
                 {                       
                                           if(year%4==0)
                                                     printf("\n Year %d  is leap",year);
                                           else
                                                     printf("\n Year %d is not leap", year);

                 }
                 getch();
 }