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

Friday 27 January 2012

Program to print day of week using switch statement.

#include<stdio.h>
#include<conio.h>
void main()
{
                 int day;
                 clrscr();
                 printf("\n Enter day in numbers 1 to 7");
                 scanf("%d",&day);
                 switch(day)
                {
                                   case 1 :
                                   printf("\n Monday");
                                   break;
                                   
                                   case 2 :
                                   printf("\n Tuesday");
                                   break;
           
                                   case 3 :
                                   printf("\n Wednesday");
                                   break;


                                   case 4 :
                                   printf("\n Thursday");
                                   break;


                                   case 5 :
                                   printf("\n Friday");
                                   break;


                                   case 6 :
                                   printf("\n Saturday");
                                   break;



                                   case 7 :
                                   printf("\n Sunday");
                                   break;

                                   
                                   defaul :
                                   printf("\n Wrong Input");
               }


}

Program to print day of week using else-if ladder.

#include<stdio.h>
#include<conio.h>
void main()
{
                  int day;
                  clrscr();
                  printf("\n Enter day of week as number from 1 to 7");
                  scanf("%d",&day);
                  if(day==1)
                          printf("\n Day of week is Monday");
                       else if(day==2)
                                  printf("Day of week is Tuesday");
                               else if(day==3)
                                           printf("Day of week is Wednesday");
                                       else if(day==4)
                                                   printf("Day of week is Thursday");
                                               else if(day==5)
                                                           printf("Day of week is Friday");
                                                       else if(day==6)
                                                                   printf("Day of week is Saturday");
                                                               else if(day==7)  
                                                                           printf("Day of week is Sunday");                                                                                                                                                                                                                                           
                                                                       else
                                                                              printf("\n Wrong Input");
                          getch();
 }  

                      

Program to find greater from three numbers.

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

Thursday 26 January 2012

Program to Calculate Compound Interest

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
                 float p,r,t,a,ci;
                 clrscr();
                 printf("\nEnter principal amount , rate of interest and time : ");
                 scanf("%f %f %f",&p,&r,&t);
                 a=p*pow((1+r/100),t);
                 ci=a-p;
                 printf("\n The compound interest  = %f",ci);
                 getch();

Greater from Two Numbers using Conditional Operator

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


NOTE:= The conditional operators (?,:)  are also called "Ternary Operators" because
                they operate on three expression. The general form of conditional operator is
                 expr1 ? expr2 : expr3.






                       

Program to Convert Fahrenheit into Centigrade Degree

#include<stdio.h>
#include<conio.h>
void main()
{
                 float fa,ce;
                 clrscr();
                 printf("\n Enter the temperature into Fahrenheit");
                 scanf("%f",&fa);
                 ce=5.0/9*(fa-32);
                 printf("\n Centigrade Degree = %f",ce);
                 getch();
}

NOTE:= You can also convert centigrade into Fahrenheit by using the formula :
                Fahrenheit = 9.0*centigrade/5+32.

Program to Calculate Square Root and Cube of a Number

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
                 int a,cb;
                 float sq;
                 printf("\n Enter a number ");
                 scanf("%d",&a);
                 sq=sqrt(a);
                 cb=pow(a,3);
                 printf(" Sqare root = %f = ",sq);
                 printf("Cube = %d",cb);
}


DESCRIPTION := In this program the in-built functions " sqrt()"  and  "pow() " are used  to calculate sqare root and cude of number.These functions are included in " math.h " header file.  

Wednesday 25 January 2012

Program to Calculate the Area of a Triangle

#include<stdio.h>
#include<conio.h>
void main()
{
int base,height;
float area;
clrscr(); // Function to clear the output screen
printf("Enter the base and height of the triangle : ");
scanf("%d %d",&base,&height);
area=0.5*base*height;
printf("The area of triangle with base %d and height %d is %f",base,height,area);
getch();
}

Program to Find Whether a Number is Even or Odd

#include<stdio.h>
#include<conio.h>
void main()
{
                 int n;
                 clrscr();
                 printf("\n Enter  a number : ");
                 scanf("%d",&n);
                 if(n%2==0)
                 printf("\n%d is even number",n);
                 else
                 printf("\n%d is odd number",n);
}

NOTE"= In "C" language "=="operator  is used for comparison  of two values.

Tuesday 24 January 2012

Program to Calculate Area and Perimeter of a Rectangle

#include<stdio.h>
#include<conio.h>
void  main()
{
                     float l,b,ar,pr;
                     printf("\n Enter length and breadth of rectangle");
                     scanf("%f %f",&l,&b); //Multiple inputs separated by space
                     ar=l*b;
                     pr=2*(l+b);
                     printf("\n Area of Rectangle = %f ",ar);
                     printf("\n Perimeter of Rectangle = %f",pr);
                     getch();
}

Program to Print the Greater from Two Numbers

#include<stdio.h>
#include<conio.h>
void main()
{
                  int a,b;
                  clrscr();
                  printf("\n Enter two numbers : ");
                  scanf(" %d %d ",&a,&b);
                  if(a>b)
                  printf(" %d  is greater ",a);
                  else
                  printf(" %d  is greater ",b);
                  getch();
}


Note : In this program we use if-else statement. In this if condition is true then if statement block is executed otherwise else statement block is executed .

Program to Print the Average of Two Numbers

#include<stdio.h>
#include<conio.h>
void main()
{
                  int a,b;
                  float avg;
                  printf("\n Enter two numbers  : ");
                  scanf("%d %d",&a,&b);
                  avg=(a+b)/2;
                  printf("\n Average = %f ",avg);
                  getch();
}

NOTE:= In this program the average of two numbers may come in fraction. So we take "avg" variable as of float(floating point) data type.

Program to exchange the value of two variables

#include<stdio.h>
#include<conio.h>
void main()
{
             int a,b,temp;
             clrscr();
             printf("\n Enter two numbers");
             scanf("%d %d ", &a, &b);
             temp=a;
             a=b;
             b=temp;
             printf("\n exchange numbers are a  = %d    b  =  %d ",a,b);
             getch();
}

Program to Print the Sum of Two Numbers Input By User

#include<stdio.h>
void main()
{
int a,b,c;
printf("Enter the value of a : ");
scanf("%d",&a);
printf("Enter the value of b : ");
scanf("%d",&b);
c=a+b; //Subtraction, Multiplication and Division can also be done
printf("The sum of a and b = %d",c);
getch();
}

Monday 23 January 2012

Program to Get the Value of a Variable from the User

#include<stdio.h>
void main()
{
int a;
printf("Enter a value : ");
scanf("%d",&a);
printf("The value entered is %d",a);
getch();
}

Program to Print Value of a Variable

#include<stdio.h>
void main()
{
int a = 10; //variable 'a' of type integer assigned value 10
printf("The value of a is %d",a);
getch();
}

Note : In the forth line the content followed by double forward slash '//' is a comment entry symbol. It is not a part of the actual code and used just to increase the readability of a program...

Sunday 22 January 2012

Program to Print "Programming Ville"

Starting with a simple program to print "Programming Ville" on the output screen :-

#include<stdio.h>
void main()
{
printf("Programming Ville");
getch();
}



Explanation:-

  • The first line is called pre-processor directive. Basically we are including a "header" file (i.e. stdio.h) that contain inbuilt functions(like printf). These lines tell the compiler to include the following files in the program while actual compilation.
  • The second line is the main function call. The "main" function is compulsory and has to be included in every program.
  • From the third line till seventh line, it is the content of the program. So they are included in "curly braces".
  • The Forth line is a function present in "stdio.h" header file. Printf is a function to print something on the output screen.
  • Getch() function in the fifth line is used to get the output on the screen.
  • The sixth line ends are program, Obviously...........



Note : If you are not aware of the functions used in the programs just search it on Google as
"[function_name] function in c". Example : "printf function in c" -OR- "getch function in c" .....
You may also read the instructions for some particular function in the Turbo C++ itself by pressing right click on that keyword in Turbo C++ IDE.

Saturday 21 January 2012

Emulated Turbo C++ Download

    It is a big problem that the most widely used operating system Windows 7 does not support full screen mode for 16bit applications, and C++ is a 16bit application. So no full screen mode in windows 7 for TC. In fact that's not true.
     There is a version(Sort of) of turbo c++ that allows us full screen mode for Windows 7
Emulated Turbo C++. The password for the zipped file is "tLvviO/oLNG#,lr"

Borland Turbo C++ Download

Though C program codes can be written just in a simple notepad file, but for making executable programs, a compiler is required!
    Here is the Borland Turbo C++ Version 3.0 compiler, the actual platform to make C programs.
The password for the zipped file is "2Xt,ZYHd#g&ZH3c"

Friday 20 January 2012

So what's Programming Ville?

       We are here not to teach you any programming languages. There are thousands of websites that can do it far better than us. So what are we here for?
     Our motive is to give you codes to all types of programs for a cross check. More specifically
"C Programs".

Few of the websites that teach C programming are here :-



  • http://www.codecademy.com/#!/exercises/0
  • http://www.cprogramming.com/challenge.html
  • http://www.howstuffworks.com/c.htm
  • http://www.cprogramming.com/tutorial/c/lesson1.html
  • http://www.cs.bris.ac.uk/Teaching/Resources/COMS30122/c/
  • http://www.codeproject.com/KB/cpp/C___Code_Optimization.aspx
  • http://www.eventhelix.com/realtimemantra/basics/optimizingcandcppcode.htm