Wednesday, December 26, 2012

What is the output?






main(){int x=4,y,z;y=--x;z=x--;printf("\n %d %d %d",x,y,z);}main(){int x=4,y=3,z;z=x-- -y;printf("\n %d %d %d",x,y,z);}main(){int i;for(i=1;i<=5;printf("\n %d",i);i++;}

Decimal number to Octal number conversion using C language


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,n1,o=0,r,p=0;
printf("\n Enter the number to convert octal number");
scanf("%d",&n);
n1=n;
while(n>0)
{
r=n%8;
n=n/8;
o=o+r*pow(10,p);
p++;
}
printf("\n The octal equivalanet number of %d is %d",n1,o);
printf("\n Press any key to exit");
getch();
}

Tuesday, December 25, 2012

Checking for Valid Triangle using C Language


/* Checking for validity of Triangle when three sides are entered*/

#include<stdio.h>
#include<conio.h>
void main()
{
int s1,s2,s3,l,s;/*s1=side one s2=side two s3=side three l=large side s=sum*/
clrscr();
printf("\n Enter the three sides of triangle");
scanf("%d %d %d",&s1,&s2,&s3);
if(s1>s2)
{
if(s1>s3)
{
s=s2+s3;
l=s1;
}
else
{
s=s1+s2;
l=s3;
}
}
else
{
if(s2>s3)
{
s=s1+s3;
l=s2;
}
else
{
s=s1+s2;
l=s3;
}
}
if(s>l)
printf("\n The triangle is valid");
else
printf("\n The triangle is invalid");
printf("\n Press any key to exit");
getch();
}

Tuesday, December 11, 2012

Program to check the Position of point from the center of circle using C language


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int x1,y1,x2,y2,r;
float dis;
clrscr();
printf("\n Enter the radius of the circle and the center coordinates");
scanf("%d%d%d",&r,&x1,&y1);
printf("\n Enter the dsired coordinate points");
scanf("%d%d%",&x2,&y2);
dis=(x2-x1)^2+(y2-y1)^2;
if(dis==(r*r))
printf("\n Enterd coordinate point lies on the circle");
else
{
if(dis>(r*r))
printf("\n Point is outside the circle");
else
printf("\n point is inside the circle");
}
printf("\n press any key to exit");
getch();
}

Monday, December 10, 2012

Checking for Collinear coordinate points in C language

#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int x1,x2,x3,y1,y2,y3;
float s1,s2,s3;
printf("\n Enter the first point coordinates");
scanf("%d%d",&x1,&y1);
printf("\n Enter the second point coordinates");
scanf("%d%d",&x2,&y2);
printf("\n Enter the third point coordinates");
scanf("%d%d",&x3,&y3);
/* calculating slope between the points*/
s1=abs(x2-x1)/abs(y2-y1);
s1=abs(x3-x1)/abs(y3-y1);
s3=abs(x3-x2)/abs(y3-y2);
if((s1==s2)&&(s1==s3))
printf("\n Points entered are collinear");
else
printf("\n Points entered are not collinear");
printf("\n Press any key to exit");
getch();
}

Sunday, December 2, 2012

Stair case of numbers using FOR loop in C++


#include<iostream.h>
#include<conio.h>
int main()
{
int i,j,c;
clrscr();
cout<<"Enter the lines"<<"\n";
cin>>c;
for(i=0;i<c;i++)
{
for(j=0;j<=i;j++)
{
cout<<i;
}
cout<<"\n";
}
return 0;
}

Swapping using reference variables as arguments in C++


#include<iostream.h>
#include<conio.h>
void swap(int &,int &);
int main()
{
int a,b;
clrscr();
cout<<"enter the values"<<"\n";
cin>>a>>b;
cout<<"Values of a and b before swapping"<<"\n";
cout<<"a="<<a<<"\n"<<"b="<<b;
swap(a,b);
cout<<"\n"<<"The values after exchange are"<<"\n";
cout<<"a="<<a<<"\n"<<"b="<<b;
return 0;
}
void swap(int &c,int &d)
{
int t;
t=c;
c=d;
d=t;
}

Larger value in two numbers using conditional operator in C++


#include<iostream.h>
int main()
{
int a,b,r;
cout<<"Enter two numbers to calculate bigger number \n";
cin>>a>>b;
r=a>b?a:b;
cout<<"The largest number is"<<r;
return 0;
}

Display string for desired number of times using C++


#include<iostream.h>
int main()
{
int a;
cout<<"Enter number of times to print string \n";
cin>>a;
for(int i=1;i<=a;i++)
{
cout<<"Well done \n";
}
return 0;
}

Conversion of Temperature from Fahrenheit to Celsius using C++


#include<iostream.h>
#include<conio.h>
int main()
{
float f,c;
cout<<"Enter the temparature in farhenheit";
cin>>f;
c=(f-32)*5/9.0;
cout<<"\n Temparature in centigrade is:"<<c;
return 0;
}

Conversion of Temperature from Fahrenheit to Celsius using classes in C++


#include<iostream.h>
#include<conio.h>
class temp
{
public:
float gett()
{
float f;
cout<<"Enter the temparature in farhenheit";
cin>>f;
return f;
}
float calc(float)
{
float c,f;
c=(f-32)*5/9.0;
return c;
}
void display(float)
{
int c;
cout<<"\n Temparature in centigrade is:"<<c;
}
};
int main()
{
float c,f;
temp t;
t.gett();
t.calc(f);
t.display(c);
return 0;
}

DC motor control with Pulse Width Modulation Part 1

DC Motor intro DC motor is a device which converts electrical energy into kinetic energy. It converts the DC power into movement. The typica...