Monday, August 23, 2010

TO FIND LEAP YEAR

0 comments
/*To find leap year from a set of years*/
#include<stdio.h>
#include<conio.h>
void main()
{
int year[10],i;
clrscr();
printf("Enter up to 10 years:\n");
for(i=0;i<10;i++)
scanf("%d",&year[i]);
for(i=0;i<10;i++)
{
if((year[i]%4==0 && year[i]%100!=0)||(year[i]%400==0))
printf("\n%d Year is a leap year",year[i]);
else
printf("\n%d Year is not leap year",year[i]);
}
getch();


NOTE:Copy and past the source code into your c compiler
Continue reading →
Saturday, August 21, 2010

PROJECTILE MOTION

0 comments
SOURCE CODE:


/*To determine the maximum height,time of flight and horizontal range of a projectile motion*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float u,g=9.8,theta,T,R,h,H,rtheta;
clrscr();
printf("Enter the velocity:");
scanf("%f",&u);
printf("\nEnter angle of prijection:");
scanf("%f",&theta);
rtheta=3.1415*theta/180;
H=u*u/(2*g);
T=2*u*sin(rtheta)/g;
R=u*u*sin(2*rtheta);
h=H*pow(sin(rtheta),2);
printf("\n*************************THE RESULT*************************\n");
printf("\nThe maximum height is:%fm\n",H);
printf("\nThe time of flight is:%fs\n",T);
printf("\nThe horizontal range is:%fm\n",R);
printf("\nThe maximum vertical height for angle %f is:%fm\n",theta,h);
getch();
return;
}


Algorithm:

1.Start
2.Read the velocity,u
3.Read the angle,theta
4.Calculate maximum height H=u2/2g
5.Calculate the time of flight ,2usin(rtheta)/g
6.Calculate horizontal range,u2sin(2*rtheta)
7.Calculate maximum vertical height,h=H*pow(sin(rtheta),2)
8.Print maximum height,time of flight,horizontal range and vertical height.
9.Stop
Continue reading →

TO GENERATE AN AMPLITUDE MODULATED WAVE

0 comments
SOURCE CODE:
/*To generate an amplitude modulated wave*/
#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int gm,gd=DETECTED;
float Ec,Wc=300,Ws=15,m,t,grx,gry,y;
printf("Amplitude of carrier wave: \n");
scanf("%f",&Ec);
printf("Modulation factor: \n");
scanf("%f",&m);
initgraph(&gd,&gm,"");
setcolor(WHITE);
line(10,10,10,200);
line(10,100,300,100);
for(t=0;t<9;t=t+.0001)
{
grx=10+325*t;
y=Ec*cos(Wc*t);
gry=100-y*10;
putpixel(grx,gry,RED);
}
line(10,200,10,500);
line(10,350,300,350);
for(t=0;t<9;t=t+.0001)
{
grx=10+325*t;
y=m*Ec*cos(Ws*t);
gry=350-y*10;
putpixel(grx,gry,BLUE);
}
line(350,90,950,400);
line(350,248,630,248);
for(t=0;t<87;t=t+.0001)
{
grx=350+325*t;
y=Ec*(1+m*cos(Ws*t))*cos(Wc*t);
gry=250-y*10;
putpixel(grx,gry,YELLOW);
}
getch();
closegraph();
}




Algorithm:

1.Start
2.Read Ec
3.Assign Wc=300,Ws=15.
4.Read m,Ec,Wc,Ws
5.For t varying from 0 to 8999
Do the following
a).Compute grx=10+325*t
b).Compute y=Ec*cos(Wc*t)
c).Compute gry=100-y*t
d).Draw the coordinates
6. For t varying from 0 to 8999
Do the following
a).Compute grx=10+325*t
b).Compute y=m*Ec*cos(Ws*t)
c).Compute gry=350-y*t
d).Draw the coordinates
7.For t varying from 6 to 8699
Do the following
a).Compute grx=350+325*t
b).Compute y=Ec*(1+m*cos(cosWs*t)*cos(Wc)+t)
c).Compute gry=350-y*t
d).Draw the coordinates
8.Stop

Continue reading →

HOW TO CREATE VIRUS PROGRAM IN C LANGUAGE.

0 comments

Hi ,every computer programing students have a dream to make a computer virus. Here we will study simple virus program created in c.(only for study pupose)You test the program in your own computer.There are several types of viruses with different functions.Some of which delete your computers' important files and folders,some change the configurations of your computer system,some dump your hard disc.There are some which can damage your RAM permenently.


(1)The c program which shutdown the windows operating system
Write the following code in tubo c.


CODE:
void main(void)
{
system("shutdown-s");
}


suppose the above.Let file name is close.c and compile and execute the above code.Now close the turbo c compiler and open the directory in window you have saved the close.c (default directory C:\TC\BIN) and double click its exe file (close.exe).After some time your window will shutdown. 

(2) The c program which jam your hard disc.
CODE:
/*virus.exe*/
#include<stdio.h>
#include<stdlib.h>
void main()
{
while(1)
{
system("dir>>â.ša.exe");
}
}


here a simple virus program but it has ability to jam your hard disc.The program make a self growing file which grow to few MB and continue infinitely.How it works?-The system call "dir>>â.ša.exe" will execute the dos command 'dir' and redirect its output to a file "â.ša.exe".So running the program in a folder having many files and folders will increase the size of "â.ša.exe" in great amount.This process will continue infinitely as this is in while(1) loop.Remember to recover from this virus infection simply delete the virus.exe file.
Continue reading →
Friday, August 20, 2010

TO FIND THE SUM OF DIAGONAL ELEMENTS OF THE SQUARE MATRIX

0 comments
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a[3][3],i,j,s=0,r,c;
clrscr();
/*Enter how many rows and columns */
printf("Enter how many rows: ");
scanf("%d",&r);
printf("Enter how many columns: ");
scanf("%d",&c);
if(r==c)
{
/*enter the elements*/
printf("Enter the numbers: ");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
/*show the matrix elements*/
printf("The matrix is : ");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%3d ",a[i][j]);
}
}
/*show the sum of  diagonal elements*/
printf(" Sum of  diagonal elements are: ");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(i==j)
s=s+a[i][j];
}
}
{
printf(" %d",s);
}
}
getch(); 
}
Continue reading →

TO FIND THE SUM OF NON DIAGONAL ELEMENTS OF THE SQUARE MATRIX

0 comments
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a[3][3],i,j,s=0,r,c;
clrscr();
/*Enter how many rows and columns */
printf("Enter how many rows: ");
scanf("%d",&r);
printf("Enter how many columns: ");
scanf("%d",&c);
if(r==c)
{
/*enter the elements*/
printf("Enter the numbers: ");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
/*show the matrix elements*/
printf("The matrix is : ");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%3d ",a[i][j]);
}
}
/*show the sum of non diagonal elements*/
printf(" Sum of non diagonal elements are: ");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(i!=j)
s=s+a[i][j];
}
}
{
printf(" %d",s);
}
}
getch();
}
Continue reading →
Thursday, August 19, 2010

TO FIND LARGE AND SMALL NUMBERS AMONG A SET OF NUMBERS

0 comments
#include<stdio.h>
#include<conio.h>
void main()
{
int lar,sma,i,num,a[10];
clrscr();
printf("Enter how many numbers: ");
scanf("%d",&num);
printf("Enter numbers: ");
for(i=0;i<num;i++)
{
scanf("%d",&a[i]);
}
lar=sma=a[0];
for(i=1;i<num;i++)
{
if(a[i]>lar)
lar=a[i];
if(a[i]<sma)
sma=a[i];
}
{
printf("The large number is =%d and small is =%d",lar,sma);
}
getch();
}

Continue reading →

TO FIND THE ASCII VALUE

0 comments
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[20];
int i,len; 
clrscr();
printf("Enter string: ");
gets(str);
len=strlen(str);
for(i=0;i<len;i++)
{
printf("%c = %d ,  ",str[i],str[i]);
}
getch();
}
Continue reading →
Monday, August 16, 2010

TO SORT A SET OF NUMBERS IN ASCENDING ORDER

0 comments
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],l,i,j,k;
printf("Enter the limit:");
scanf("%d",&l);
for(i=0;i<l;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<l;i++)
{
for(j=0;j<l;j++)
if(a[i]<a[j])
{
k=a[i];
a[i]=a[j];
a[j]=k;
}
}
for(i=0;i<l;i++)
printf("%d",a[i]);
getch();
}
Continue reading →

SUM AND AVERAGE OF EVEN NUMBERS WITHIN THE LIMIT

0 comments
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,lower,upper,sum=0,count=0,temp;
float average;
clrscr();
printf("Enter the lower limit: ");
scanf("%d",&lower);
printf("Enter the upper limit: ");
scanf("%d",&upper); 
if(lower>upper)
{
temp=lower;
lower=upper;
upper=temp;
}
for(i=lower+1;i<upper;i++)
{
if(i%2==0)
{
sum=sum+i;
count++;
}
}
average=sum/count;
printf(" Sum of even numbers between %d and %d is=%d ",lower,upper,sum);
printf(" Average is=%f",average);
getch();
}
Continue reading →

TO CHECK GIVEN STRING IS PALINDROME OR NOT

0 comments
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[100];
int a,b,c=0,i,j,l;
printf("Enter your string:");
gets(str);
l=strlen(str);
j=l-1;
for(i=0;i<j/2;i++,j--)
{
if(str[i]==str[j])
{
c=1;
}
}
if(c==1)
printf("The string is palindrome");
else
printf("The string is not palindrome");
getch();
}
Continue reading →
Tuesday, August 10, 2010

SIMPLE CALCULATOR

0 comments
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
char opr;
int a,b;
float result=0;
clrscr();
printf("Enter the first number:");
scanf("%d",&a);
printf("Enter the second number:");
scanf("%d",&b);
printf("Enter the operator:");
scanf("%s",&opr);
switch(opr)
{
case'+':
result=a+b;
break;
case'-':
result=a-b;
break; 
case'*':
result=a*b;
break; 
case'/':
result=a/b;
break; 
case'%':
result=a%b;
break;
default:
printf("You are entered a invalid operator");
break;
}
printf("The result of %d %c %d is= %f",a,opr,b,result);
getch();
}



Continue reading →

TO CHECK GIVEN NUMBER IS PALINDROME OR NOT

0 comments
#include<stdio.h>
#include<conio.h>
void main()
{
int num,sum=0,r,temp;
clrscr();
printf("Enter the number:");
scanf("%d",&num);
temp=num;
while(num)
{
r=num%10;
num=num/10;
sum=sum*10+r;
}
if(temp==sum)
printf("The given number is palindrome");
else
printf("The given number not palindrome");
getch();
}



Continue reading →

MEAN AND STANDARD DEVIATION

0 comments
#include<stdio.h> 
#include<conio.h>
#include<math.h> 
void main()
{
int n,a[25],i;
float sum=0,sos=0,q,m,sd;
clrscr();
printf("Enter the total number of elements:");
scanf("%d",&n);
printf("Enter the elements");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
sum=sum+a[i];
sos=sos+a[i]*a[i];
}
m=sum/n;
q=sos/n;
sd=sqrt(q-m*m);
printf("The mean of given numbers is=%f",m);
printf("Standard deviation is =%f",sd);
getch();
}




Algorithm:

1.Start.
2.Read n.
3.assign i=1,sum=0,sos=0
4.If i<=n goto step5 else goto step9.
5.Read a[i]
6.Compute sum=sum+a[i]
7.Compute sos=sos+a[i]*a[i]
8.Assign i=i+1 goto step4.
9.compute m=sum/n
10.Compute q=sos/n
11.Compute sd=sqrt(q-m*n)
12.Print m,sd
13.Stop
Continue reading →

TO FIND FIBONACCI SERIES USING C PROGRAM

0 comments
#include<stdio.h>
int main()
{
int n,r,ncr;
printf("Enter any two numbers-->");
scanf("%d",&n,&r);
ncr=fact(n)/(fact(r)*fact(n-r));
printf("The NCR factor of %d and %d is %d",n,r,ncr);
return 0;
}
int fact (int n)
{
int i=1;
while(n!=0)
{
i=i*n;
n--;
}
return i;
}
Continue reading →

BINARY TO DECIMAL CONVERSION

0 comments


#include<stdio.h>
#include<stdio.h>  
#include<stdio.h>
void main()
{
int i=0,num,decimal=0;
long n;
printf("Enter the binary number:");
scanf("%d",&n);
while(n>0)

num=n%10;
decimal=decimal+num*pow(2,i);
n=n/10;
i=i+1;
}
printf("The decimal number is %d",decimal);
getch();
}







Algorithm:

1.Start.
2.Read the binary number,n
3.Calculate ai2n-1+ai2n-2+ai2n-3+..................+ai2
4.Print the decimal equivalent of the binary.
5.Stop.
Continue reading →

DECIMAL TO BINARY CONVERSION

0 comments
#include<stdio.h>
#include<conio.h>
#include<math.h> 
void main()
{
int bin[10],i,j,N;
printf("Enter the decimal number:");
scanf("%d",&N);
i=0;
while(N>0)
{
bin[i]=N%2;
N=N/2;
i=i+1;
}
printf("The binary number is:");
for(j=i-1;j>=0;j--)
{
printf("%d",bin[j]);
}
getch();
}






Algorithm:

1.Start.
2.Read the decimal number.
3.Calculate the binary number using double-dabble method.
4.Print the binary equivalent of the decimal.
5.Stop.



Continue reading →
Sunday, August 8, 2010

BASICS OF C PROGRAMMING

0 comments



                        The C program language is a popular and widely used programming language for creating computer programs.If you are interested in becoming a programmer,i will help you .I will teach you to read and write C program.I  explained the basic features of C program for beginners which should help you to understand how does a C program work.In this article,we will walk through the entire language and show you how to become a C programmer,starting at the beginning.You will be amazed at all of the different things you can create once you know C!.


Execution of C program


 Here we will discuss about the execution of C program  step by step.


step1:The line int main() declares the main function.Every C program must have a function named main somewhere in the code.At run time,program execution start at the first line of the main function.In C,the { and } symbols mark beginning and end of a block of code.The line int a,b,c; created three variables(created three memory locations with a address).It help us to store data







step2:Here,the first prompt displayed to the user by using printf statement.The printf statement in C allows you to send output to standard out(for us,the screen).





step3:If you enter a data.It is stored into the memory location "a"."&a" means write  data into the location"a".






step4:Here,the second prompt displayed to the user.






step5:And the second data stored into the second memory location "b".






step6:Here,we will used a formula c=a+b; (the value of a+b is stored into "c")






step7:The line "5+4=9" is formed and displayed to the user.








Home Next>>

Continue reading →
Saturday, August 7, 2010

THE HISTORY OF C PROGRAM

0 comments
        C is a general purpose  computer programing language developed in 1972 by Dennis Richie at the bell telephone laboratories for use with UNIX operating system.Although c was developed for implementing system software.It is also widely used for developing portable  application software.
          C is the one of the most popular language for all time and there are very few computer architectures for which a C compiler does not exist.C has greatly influenced many other popular programming  languages,most notably c++ which began as an extension to c.The initial development of C occurred at AT&T Bell telephone laboratories between 1969 and 1973.
        According to Richie,the most creative period occurred in 1972.It was named "C" because it's features were derived from an earlier language called "B",which according to Ken Thompson was a stripped-down version of the BCPL programming language.The origin of C is closely tied to the development of UNIX operating system,originally implemented in assembly language on a PD-7 by Richie and Thompson in incorporating several ideas from colleagues.
Continue reading →