Tuesday, 7 May 2013

Program In C To Find Sum Of Digits Of A Number Using Recursion

#include<stdio.h>
#include<conio.h>
int fun(int num)
{ int rem,sum;
if(num==0)
return 0;
else
{ rem=num%10;
sum=rem+fun(num/=10); }
return sum;
}
void main()
{ int n,sod;
clrscr();
printf("Enter Number: ");
scanf("%d",&n);
sod=fun(n);
printf("Sum Of Digits Is: %d",sod);
getch();
}

Program In C To Calculate Size Of Different Data Types


#include <stdio.h>
#include <conio.h>

int main(){

int *a;
printf("\nSIZE OF DIFFERENT DATA TYPES\n");
printf("\n------------------------------");
printf("\n\tBASIC");
printf("\n------------------------------");
printf("\nCHARACTER \t: %d byte(s)",sizeof(char));
printf("\nSHORT \t\t: %d byte(s)",sizeof(short));
printf("\nINTEGER \t: %d byte(s)",sizeof(int));
printf("\nLONG \t\t: %d byte(s)",sizeof(long));
printf("\nFLOAT \t\t: %d byte(s)",sizeof(float));
printf("\nDOUBLE \t\t: %d byte(s)",sizeof(double));
printf("\nLONG DOUBLE \t: %d byte(s)",sizeof(long double));
printf("\nLONG LONG \t: %d byte(s)",sizeof(long));
printf("\nPOINTER (any) \t: %d byte(s)",sizeof(*a));
printf("\nARRAY \t\t: sizeOfDataType * sizeOfArray [eg. int a[10]=%d byte(s)]",sizeof(int)*10);
printf("\n------------------------------");

return 0;
}

Program In C To Calculate sin,cos and tan values for an angle


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float n,a,b,c;
clrscr();
printf("Enter the value for the angle: ");
scanf("%f",&n);
a=sin(n);
b=cos(n);
c=tan(n);
printf("Sin(%f) is: %2.2f\n",n,a);
printf("Cos(%f) is: %2.2f\n",n,b);
printf("Tan(%f) is: %2.2f\n",n,c);
getch();
}

Program In C To Check Whether A Number Is Prime Number Or Not


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{ int num,i;
clrscr();
printf("Enter Number: ");
scanf("%d",&num);
if(num==1)
{printf("It Is Not A Prime Number");
exit(0);}
for(i=2;i<=((num/2)+1);i++)
{ if(num%i==0)
{ printf("It Is Not A Prime Number");
break;}
else if(i==(num/2)+1)
printf("It Is A Prime Number");
}
getch();
}

Program In C To Calculate exponential power i.e. e(x,y) using recursion


#include<stdio.h>
#include<conio.h>
int fun( int x, int y)
{ int z;
if(y==0)
return 1;
else
z=x*fun(x,y-1);
return z;
}
void main()
{ int a,b,c;
printf("Enter base: ");
scanf("%d",&a);
printf("Enter exponent: ");
scanf("%d",&b);
c=fun(a,b);
printf("Answer Is: %d",c);
getch();
}

Program In C To Find Out Quadrant Of An Angle


#include<stdio.h>
int main(void)
{
int angle;
 printf("enter an angle in degrees:");
scanf("%d",&angle);
angle=angle%360;
if(angle%90==0) printf("angle %d lies on an axis\n",angle);
else
if( angle >0 && angle <90)
{
printf("\nThe angle is in quadrant I");
}
else if( angle >90 && angle <180)
{
printf("\nThe angle is in quadrant II");
}
else if(angle >180 && angle <270)
{
printf("\nThe angle is in quadrant III");
}
else if (angle >270 && angle <360 )
{
printf("\nThe angle is in quadrant IV");
}

if(angle%90==0)
switch(angle/90){

case 0: printf("\nThe angle is on the positive X axis");
break;
case 1:
printf("\nThe angle is on the positive Y axis");
break;
case 2:
printf("\nThe angle is on the negative X axis");
break;
case 3:
printf("\nThe angle is on the negative Y axis");
break;
default:
printf("error");
}
return 0;
}

Program In C To Print Next Date


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{ int d1,m1,d2,m2,y1,y2;
clrscr();
printf("Enter The Date: ");
scanf("%d",&d1);
printf("Enter The Month: ");
scanf("%d",&m1);
printf("Enter The Year: ");
scanf("%d",&y1);
if((d1>=1&&d1<28))
{ d2=d1+1;
m2=m1;
y2=y1; }
else if((d1==31)&&(m1==1||m1==3||m1==5||m1==7||m1==8||m1==10||m1==12))
{ d2=1;
 if(m1==12)
{
m2=1;
y2=y1+1; }
else
{ m2=m1+1;
y2=y1; }}
else if((m1==2)&&(d1<30))
{ if((y1%4==0&&d1==29)||(y1%4!=0&&d1==28))
{ d2=1;
m2=3;
y2=y1; }
else if(d1<29)
{ d2=d1+1;
m2=2;
y2=y1; }}
else if((d1==30)&&(m1==4||m1==6||m1==9||m1==11))
{d2=1;
m2=m1+1;
y2=y1; }
else if((m1<13&&d1<31)&&(m1!=2))
{ d2=d1+1;
m2=m1;
y2=y1;
}
else
{ printf("Wrong Date !!!!!");
exit(0);
}
printf("Next Date Is: %d.%d.%d",d2,m2,y2);
getch();
}

Program In C For Bubble Sorting



#include <stdio.h>
#include<conio.h>

void main()
{
  int array[100], n, c, d, swap;
  clrscr();

  printf("Enter number of elements\n");
  scanf("%d", &n);

  printf("Enter %d integers\n", n);

  for (c = 0; c < n; c++)
scanf("%d", &array[c]);

  for (c = 0 ; c < ( n - 1 ); c++)
  {
for (d = 0 ; d < n - c - 1; d++)
{
if (array[d] > array[d+1])
{
 swap       = array[d];
 array[d]   = array[d+1];
 array[d+1] = swap;
}
}
  }

  printf("Sorted list in ascending order:\n");

  for ( c = 0 ; c < n ; c++ )
 printf("%d\n", array[c]);
getch();

}

Program In C To Find Factorial Of A Number Using Recursion


#include<stdio.h>

int func(int x)

{

int f;
if (x==1)
return (1);
else
f=x*func(x-1);
return (f);
}
void main()

{

int a, fact;



printf("\nEnter any number: ");

scanf ("%d", &a);

fact=func(a);

printf("\nFactorial Value = %d", fact);



}


Program In C For Binary Search


#include <stdio.h>

void main()
{
   int c, first, last, middle, n, search, array[100];

   printf("Enter number of elements\n");
   scanf("%d",&n);

   printf("Enter %d integers\n", n);

   for ( c = 0 ; c < n ; c++ )
      scanf("%d",&array[c]);

   printf("Enter value to find\n");
   scanf("%d",&search);

   first = 0;
   last = n - 1;
   middle = (first+last)/2;

   while( first <= last )
   {
      if ( array[middle] < search )
         first = middle + 1;  
      else if ( array[middle] == search )
      {
         printf("%d found at location %d.\n", search, middle+1);
         break;
      }
      else
         last = middle - 1;

      middle = (first + last)/2;
   }
   if ( first > last )
      printf("Not found! %d is not present in the list.\n", search);

   
}

Monday, 6 May 2013

Download Free C/C++ Compiler For Windows 7, xp, vista

Click  Below To Download Free Turbo C/C++ compiler

Download


  • NameTurbo C++
  • Version3.0
  • LicenseFree 
  • CompatibilityWindows Me, Windows 2000, Windows Vista, 

  • Windows 7, Windows XP, Windows NT

Program In C to Check Whether A Number Is Armstrong Number Or Not


#include<stdio.h>
#include<conio.h>
void main()
{
int num,r,sum=0,temp;
clrscr();

printf("Enter a number: ");
scanf("%d",&num);

temp=num;
while(num!=0)
{
r=num%10;
num=num/10;
sum=sum+(r*r*r);
}
if(sum==temp)
printf("%d is an Armstrong number",temp);
else
printf("%d is not an Armstrong number",temp);

getch();
}

Program In C to Check Whether A Number IS Palindrome Or Not


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d;
clrscr();
printf(" Enter a  number\n");
scanf("%d" , &a);
c=0;
d=a;
while(a>0)
{
b=a%10 ;
c=(c*10)+b ;
a=a/10;
}
if(c==d)                                              
{
printf(" Number Is palindrome ");
}
else
{
printf(" Number is not palindrome ");
}
getch();
}

Sunday, 5 May 2013

Program In C++ to calculate Area of Circle

#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
float r,a;
cout<<"enter radius ";
cin>>r;
a=3.14*r*r;
cout<<"The area is "<<a;
getch();
}

Program In C to calculate Area of Circle

#include<stdio.h>
#include<conio.h>
void main()
{
float radius,area;
clrscr();  // Clear Screen

printf("\nEnter the radius of Circle : ");
scanf("%d",&radius);

area = 3.14 * radius * radius;

printf("\nArea of Circle : %f",area);
getch();
}

Program In C++ To Calculate Simple Interest


#include<iostream.h>
#include<conio.h>

int main()
{
int p,r,t,i;
cout<<"Enter Principle : ";
cin>>p;
cout<<"Enter Rate : ";
cin>>r;
cout<<"Enter Time : ";
cin>>t;
i=(p*r*t)/100;
cout<<"Simple interest is : "<<i;

getch();
return 0;
}

Program In C To Calculate Simple Interest


#include<stdio.h>
#include<conio.h>
void main()
{
float p,r,n,si;
clrscr();
printf("\nEnter the profit, rate & no of yr\n\n ");
scanf("%f%f%f",&p,&r,&n);
si=(p*r*n)/100;
printf("\nSimple Intrest=%f",si);
getch();
}

Program In C++ to Add Two Numbers

Here's The Code In C++ To Add Two Number

#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int a,b,c;
cout<<"Enter two numbers to add\n";
cin>>a>>b;
c = a+b;
cout<<"Sum of entered numbers = " << c << endl;
getch();
}

Program In C To Add Two Numbers

Here's The Code In C To Add Two Numbers :

#include<stdio.h>
#include<conio.h>
void main()
{ int a,b,sum;
clrscr();
printf("Enter 1st Number: ");
scanf("%d",&a);
printf("Enter 2nd Number: ");
scanf("%d",&b);
sum=a+b;
printf("Sum Of 2 Numbers Is: %d",sum);
getch();
}