Sunday, 30 September 2012

Simple C programs





  1.  Program to print the series 5,10,15,...........n.

#include<stdio.h>
main()
{
int n,i;
clrscr();
printf("Enter the value of n\n");
scanf("%d",&n);
printf("The Series is\n");
for(i=5;i<=n;i+=5)
printf("%d\n",i);
getch();
}

2. Program to print the sum of the series 2,4,6,...........n

#include<stdio.h>
main()
{
int n,i,sum=0;
clrscr();
printf("Enter the value of n\n");
scanf("%d",&n);
for(i=0;i<=n;i+=2)
sum=sum+i;
printf("The sum of the series is %d\n",sum);
getch();
}

3. Program to count the number of digits in a given number.

#include<stdio.h>
main()
{
int n,count=0;
clrscr();
printf("Enter the value of n\n");
scanf("%d",&n);
while(n!=0)
{
n=n/10;
count++;
}
printf("The no of digits are %d\n",count);
getch();
}

4. Program to sum of individual digits of a given number.

#include<stdio.h>
main()
{
int n,sum=0,d;
clrscr();
printf("Enter the value of n\n");
scanf("%d",&n);
while(n!=0)
{
d=n%10;
sum=sum+d;
n=n/10;
}
printf("The sum of the individual digits is %d\n",sum);
getch();
}

5. Program to find and circumference giving radius.

#include<stdio.h>
main()
{
float r,area,cir;
clrscr();
printf("Enter the radius value\n");
scanf("%f",&r);
area=3.14*r*r;
cir=2*3.14*r;
printf("The area is %f\n",area);
printf("The circumference is %f\n",cir);
getch();
}

6. Program to find final velocity and distance giving initial velocity,acceleration and time.

#include<stdio.h>
main()
{
float u,a,t,fv,d;
clrscr();
printf("Enter the initial velocity,accelaration and time value\n");
scanf("%f%f%f",&u,&a,&t);
fv=u+(a*t);
d=(u*t)+(0.5*a*t*t);
printf("The final velocity is %f\n",fv);
printf("The distance is %f\n",d);
getch();
}

7. Program to find area of a triangle giving its sides.

#include<stdio.h>
main()
{
int s1,s2,s3,s,area;
clrscr();
printf("Enter sides of the triangle\n");
scanf("%d%d%d",&s1,&s2,&s3);
s=(s1+s2+s3)/3;
area=sqrt(s*(s-s1)*(s-s2)*(s-s3));
printf("The area fo the triangle %d\n",area);
getch();
}

8. Program to convert foreign heat into celcius and vice versa.

#include<stdio.h>
main()
{
float f,c;
clrscr();
printf("Enter the forein heat");
scanf("%f",&f);
c=(f*1.8)+32;
printf("The celcius= %f\n",c);
printf("Enter the celcius");
scanf("%f",&c);
f=(c-32)/1.8;
printf("The foreign heat %f\n",f);
getch();
}

9. Program to find sum,squares sum,cubes sum of n natural numbers.

#include<stdio.h>
main()
{
int s,ss,sss,n;
clrscr();
printf("Enter the value of n");
scanf("%d",&n);
s=(n*(n+1))/2;
printf("The sum of n natural numbers= %d\n",s);
ss=n*(n+1)*(2*n+1)/6;
printf("The sum of squares of n natural numbers= %d\n",&ss);
sss=s*s;
printf("The cubers of n natural numbers is %d\n",sss);
getch();
}

10. Program to find standard deviation giving x1,x2,x3.

#include<stdio.h>
#include<math.h>
main()
{
int d1,d2,d3,x1,x2,x3,s,avg;
clrscr();
printf("Enter the values of x1,x2,x3\n");
scanf("%d%d%d",&x1,&x2,&x3);
avg=(x1+x2+x3)/3;
d1=x1-avg;
d2=x2-avg;
d3=x3-avg;
s=sqrt((d1*d1)+(d2*d2)+(d3*d3));
printf("The average is = %d\n", avg);
printf("The standard deviation is %d",s);
getch();
}

11.  Program to interchange two values using and without using third variable.

#include<stdio.h>
main()
{
int a,b,c,i;
clrscr();
printf("Enter the values of a,b\n");
scanf("%d%d",&a,&b);
printf(" \t1. Using third variable \n");
printf(" \t2. Without using third variable\n");
printf(" \t3. Exit \n");
printf("\n Enter Your Choice  : ");
scanf("%d",&i);
switch(i)
{
case 1 : c=a;
             a=b;
             b=c;
             printf("The values a = %d b = %d",a,b);
             break;

case 2 : a=a+b;
 b=a-b;
             a=a-b;
             printf("The values a = %d b = %d",a,b);
             break;
default : break;
}
getch();
}

12. Program to read time in seconds and print them in hours,miniutes and seconds.

#include<stdio.h>
main()
{
int s,h,m;
clrscr();
printf("Enter the seconds\n");
scanf("%d",&s);
m=s/60;
h=s/3600;
printf( "Hours = %d Miniutes = %d Seconds = %d", h,m,s);
getch();
}

13. Program to read two co-ordinates and print the distance between them.

#include<stdio.h>
#include<math.h>
main()
{
int x1,y1,x2,y2,d=0;
clrscr();
printf("Enter the values of the co-ordinates\n");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
x1-=x2;
y1-=y2;
d=sqrt((x1*x1)+(y1*y1));
printf("The distance Between the Co-ordinates= %d",d);
getch();
}

14. Program to print the reverse of the given number.

#include<stdio.h>
main()
{
int n,s=0,d;
clrscr();
printf("Enter the n value\n");
scanf("%d",&n);
while(n!=0)
{
d=n%10;
s=s*10+d;
n/=10;
}
printf("The reverse of the given number is = %d",s);
getch();
}

15. Program to find the largest of given three numbers.

#include<stdio.h>
main()
{
int a,b,c;
clrscr();
printf("Enter the a,b,c values\n");
scanf("%d%d%d",&a,&b,&c);
if(a>b&&a>c)
printf("A is greater");
else
if(b>c&&b>c)
printf("B is greater");
else
printf("C is greater");
getch();
}

16. Program to check weather the given number is palindrome or not.

#include<stdio.h>
main()
{
int n,s=0,d,k;
clrscr();
printf("Enter the n value\n");
scanf("%d",&n);
k=n;
while(n!=0)
{
d=n%10;
s=s*10+d;
n/=10;
}
if(s==k)
printf("The given number is palindrome");
else
printf("The given number is not a palindrome");
getch();
}

17.  Program to read customer name,number and consumed units and print the amount under below conditions.

                        Consumption Units     Rate of charge

                            0-200                       Rs.0.50 per unit
                          201-400                     Rs.100+Rs.0.65 per unit excess of 200
                          401-600                     Rs.230+Rs.0.85 per unit excess of 400
                          601 and above           Rs.390+Ss.1.00 per unit excess of 600

#include<stdio.h>
main()
{
char cname;
int cno,cu,d;
float net=0;
clrscr();
printf("Enter the Customer name\n");
scanf("%s",&cname);
printf("Enter the customer number\n");
scanf("%d",&cno);
printf("Enter the consumption units\n");
scanf("%d",&cu);
if(cu<=200)
net=cu*0.50;
else
if(cu>200 && cu<400)
{
d=cu-200;
net=100+(d*0.65);
}
else
if(cu>400 && cu<600)
{
d=cu-400;
net=230+(d*0.85);
}
else
if(cu>600)
{
d=cu-600;
net=390+(d*1.00);
}
printf("The net amount= %f",net);
getch();
}

18. Program to find the factors of the given number .

#include<stdio.h>
main()
{
int n,i;
clrscr();
printf("Enter the value of n\n");
scanf("%d",&n);
printf("The factors of %d are\n",n);
for(i=2;i<n;i++)
{
if(n%i==0)
printf("%d\n",i);
}
getch();
}

19. Program to find whether the given number is perfect or not.

#include<stdio.h>
main()
{
int n,i,sum;
clrscr();
printf("Enter the value of n\n");
scanf("%d",&n);
printf("The factors of %d are\n",n);
for(i=2;i<n/2;i++)
{
if(n%i==0)
{
printf("%d\n",i);
sum=sum+i;
}
}
if(sum==n)
printf("The given number is perfect");
else
printf("The given number is not perfect");
getch();
}

20. Program to find the sum of all integers greater than 100 and less than 200 divisible by 7.

#include<stdio.h>
main()
{
int i,sum;

clrscr();
for(i=100;i<=200;i++)
{
if(i%7==0)
sum+=i;
}
printf("The sum is %d",sum);
getch();
}

21. Program to find the factorial of the given number.

#include<stdio.h>
main()
{
int i,fact=1,n;
clrscr();
printf("Enter the value of n");
scanf("%d",&n);
for(i=2;i<=n;i++)
fact*=i;
printf("The factorial of %d is %d",n,fact);
getch();
}

22. Program to find whether the given number is prime or not.

#include<stdio.h>
main()
{
int i,n,k=0;
clrscr();
printf("Enter the value of n\n");
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
k=1;
}
if(k==0)
printf("Prime number");
else
printf("Not a prime number");
getch();
}

23. Program to print the fibonacci series 0,1,1,2,3,5,8,...…

#include<stdio.h>
main()
{
int f1=0,f2=1,f3,n,i;
clrscr();
printf("Enter the value of n\n");
scanf("%d",&n);
printf("The fibonacci series is\n");
printf("%d\n%d\n",f1,f2);
for(i=0;i<n;i++)
{
f3=f1+f2;
printf("%d\n",f3);
f1=f2;
f2=f3;
}
getch();
}

24. Program to find the solution of bionamial equation ncr=n!/(n-r)!r! .

#include<stdio.h>
main()
{
int i,ncr=0,fact=1,fact1=1,rfact=1,n,r;
clrscr();
printf("Enter the value of n and r\n");
scanf("%d\n%d",&n,&r);
for(i=2;i<=n;i++)
{
fact*=i;
}
for(i=2;i<=r;i++)
{
rfact*=i;
}
for(i=2;i<=(n-r);i++)
{
fact1*=i;
}
ncr=fact/(fact1*rfact);
printf("The value of ncr is %d", ncr);
getch();
}

25. Program to find GCD of two numbers.

#include<stdio.h>
main()
{
int m,n,r;
clrscr();
printf("Enter the value of m and n\n");
scanf("%d\n%d",&m,&n);
r=m%n;
while(r!=0)
{
m=n;
n=r;
r=m%n;
}
printf("The GCD of two numbers is %d",n);
getch();
}

26. Program to find LCM of two numbers.

#include<stdio.h>
main()
{
int m,n,r,p;
clrscr();
printf("Enter the value of m and n\n");
scanf("%d\n%d",&m,&n);
p=m*n
r=m%n;
while(r!=0)
{
m=n;
n=r;
r=m%n;
}
lcm=p/n;
printf("The LCM of two numbers is %d",lcm);
getch();
}

27. Program to find grade of the student.

#include<stdio.h>
main()
{
int s1,s2,s3,avg,grade,sno;
clrscr();
printf("Enter the Student number\n");
scanf("%d",&sno);
printf("Enter the marks of the student in s1,s2 and s3\n");
scanf("%d\n%d\n%d",&s1,&s2,&s3);
avg=(s1+s2+s3)/3;
if(avg<35)
printf("Fail");
else
if(avg>=35 && avg<50)
                                    printf("Third Class");
else
if(avg>=50 && avg<60)
printf("Second Class");
else
printf("First class");
getch();
}


28. Program to find the net amount of the employee.

#include<stdio.h>
main()
{
int eno;
float hra,da,ta,pf,tax,gross=0,basic;
clrscr();
printf("Enter the Employee number\n");
scanf("%d",&eno);
printf("Enter the Basic pay of the Employee\n");
scanf("%f",&basic);
da=(17.0/100)*basic;
ta=(10.0/100)*basic;
hra=(5.0/100)*basic;
tax=(6.0/100)*basic;
pf=(8.0/100)*basic;
gross=(hra+ta+da+basic)-(tax+pf);
printf("The Net amount of the Employee is %f", gross);
getch();
}

29. Program to print the given number in words.

#include<stdio.h>
main()
{
int n,i,d,s=0;
clrscr();
printf("Enter the number\n");
scanf("%d",&n);
while(n!=0)
{
d=n%10;
s=s*10+d;
n/=10;
}
while(s!=0)
{
i=s%10;
switch(i)
{
case 0 : printf("ZERO\t");
             break;
case 1 : printf("ONE\t");
                                                 break;
case 2 : printf("TWO\t");
             break;
case 3: printf("THREE\t");
             break;
case 4 : printf("FOUR\t");
             break;
case 5 : printf("FIVE\t");
             break;
case 6 : printf("SIX\t");
             break;
case 7 : printf("SEVEN\t");
             break;
case 8 : printf("EIGHT\t");
             break;
case 9 : printf("NINE\t");
             break;
default : break;
}
s/=10;
}
            getch();
}

30. Program to read a list of elements and display them.

#include<stdio.h>
main()
{
int a[10],i;
clrscr();
printf("Enter the elements\n");
for(i=0;i<=10;i++)
scanf("%d",&a[i]);
printf("The elements are\n");
for(i=0;i<=10;i++)
printf("%d\n",a[i]);
getch();
}

31. Program to read a single line and print them.

#include<stdio.h>
main()
{
char s;
clrscr();
printf("Enter the String\n");
scanf("%s",s);
printf("The given string is\n");
printf("%s",s);
getch();
}

32. Program to find the largest and smallest of given list of elements.

#include<stdio.h>
main()
{
int a[80],n,i,lar,sma;
clrscr();
printf("Enter the value of n\n");
scanf("%d",&n);
printf("Enter the elements\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
            lar=sma=a[1];
for(i=1;i<=n;i++)
{
if(a[i]>lar)
lar=a[i];
if(a[i]<sma)
sma=a[i];
}
printf("The largest = %d\n",lar);
printf("The smallest = %d",sma);
getch();
}

33. Program to search an element by linear search.

#include<stdio.h>
main()
{
int a[80],n,i,key,k=1;
clrscr();
printf("Enter the value of n\n");
scanf("%d",&n);
printf("Enter the elements\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("Enter the key element = ");
scanf("%d",&key);
for(i=1;i<=n;i++)
{
if(a[i]==key)
k=0;
}
if(k==0)
printf("Searching is successful\n");
else
printf("Searching is Unsuccessful");
getch();
}

34. Program to search an element by binary search.

#include<stdio.h>
main()
{
int a[80],n,i,low,high,mid,loc,key;
clrscr();
printf("Enter the value of n\n");
scanf("%d",&n);
printf("Enter the elements\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("Enter the key element = ");
scanf("%d",&key);
low=1;high=n;
mid=(low+high)/2;
while(a[mid]!=key && (low<=high))
{
if(a[mid]<key)
 low=mid+1;
else
 high=mid-1;
 mid=(low+high)/2;
 }
if(a[mid]==key)
loc=0;
else
loc=1;
if(loc==0)
printf("Searching is successful\n");
else
printf("Searching is Unsuccessful");
getch();
}

35. Program to insert an element in desired location.

#include<stdio.h>
main()
{
int a[80],n,i,loc,ele;
clrscr();
printf("Enter the value of n\n");
scanf("%d",&n);
printf("Enter the elements\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("Enter the location ");
scanf("%d",&loc);
printf("Enter the element");
scanf("%d",&ele);
for(i=n+1;i>loc;i++)
a[i]=a[i-1];
loc=ele;
printf("The elements are");
for(i=1;i<=n+1;i++)
printf("%d",a[i]);
getch();
}

36. Program to arrange the elements in ascending order and descending order.

#include<stdio.h>
main()
{
int a[80],n,i,j,temp;
clrscr();
printf("Enter the value of n\n");
scanf("%d",&n);
printf("Enter the elements\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("The elements in ascending order are\n");
for(i=1;i<=n;i++)
printf("%d\n",a[i]);
printf("The elements in descending order are\n");
for(i=n;i>0;i--)
printf("%d\n",a[i]);
getch();
}

37. Program to find the solution e^x=1+x+x^2/2!+.......

#include<stdio.h>
main()
{
int n,i,x,ex,term=1,prod=1;
clrscr();
printf("Enter the value of x and n\n");
scanf("%d%d",&x,&n);
for(i=0;i<=n;i++)
{
ex= ex+(term/prod);
term*=x;
prod*=i;
}
printf("The value of ex = %d ", ex);
getch();
}

38. Program to find the solution cosx=x-x^2/2!+x^4/4!-.......

#include<stdio.h>
main()
{
int n,j=1,i,x,term=1,prod=1,sign=-1;
float cx=0;
clrscr();
printf("Enter the value of x and n\n");
scanf("%d%d",&x,&n);
for(i=1;i<=n;i++)
{
cx+=term*sign/prod;
term*=x*x;
prod*=(j+1)*(j+2);
j+=2;
}
printf("The value of cosx = %f ", cx);
getch();
}

39. Program to find the addition of two matices.

#include<stdio.h>
main()
{
int a[80][80],b[80][80],c[80][80],m,n,i,j;
clrscr();
printf("Enter the row and coloumn numbers\n ");
scanf("%d%d",&m,&n);
printf("Enter the elements of matrix a\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n");
}
printf("Enter the elements of thematrix b\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&b[i][j]);
printf("\n");
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("The addition of the matrices\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
getch();
}


40. Program to find the largest number in a two dimensional array a[0..n-1,0..n-1].

#include<stdio.h>
main()
{
int a[80][80],lar,m,n,i,j;
clrscr();
printf("Enter the row and coloumn numbers\n");
scanf("%d%d",&m,&n);
printf("Enter the elements of the matrix \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n");
}
lar=a[0][0];
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(lar<a[i][j])
lar=a[i][j];
}
}
printf("The largest element of the matrix = %d",lar);
getch();
}

41. Program to find the sum of the diagonals of a two dimensional array.

#include<stdio.h>
main()
{
int a[80][80],sum=0,m,n,i,j;
clrscr();
printf("Enter the row and coloumn numbers\n");
scanf("%d%d",&m,&n);
printf("Enter the elements of the matrix \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n");
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
sum+=a[i][j];
}
}
            printf("The sum of the diagonal elements of the matrix = %d",sum);
getch();
}
42. Program to find the multiplication of two matices.

#include<stdio.h>
main()
{
int a[80][80],b[80][80],c[80][80],m,n,n1,k,p,i,j;
clrscr();
printf("Enter the row and coloumn numbers of first matrix\n ");
scanf("%d%d",&m,&n);
printf("Enter the row and coloumn numbers of first matrix\n ");
scanf("%d%d",&n1,&k);
printf("Enter the elements of matrix a\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n");
}
printf("Enter the elements of thematrix b\n");
for(i=0;i<n1;i++)
{
for(j=0;j<k;j++)
{
scanf("%d",&b[i][j]);
}
printf("\n");
}
if(n==n1)
{
for(i=0;i<m;i++)
{
for(j=0;j<k;j++)
{
c[i][j]=0;
for(p=1;p<=n;p++)
{
c[i][j]+=a[i][j]*b[i][j];
}
}
}
}
else
            {
printf("Multiplication is not posible");
getch();
exit();
}
printf("The multiplication of the matrices\n");
for(i=0;i<m;i++)
{
                        for(j=0;j<n;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
getch();
}

43. Program to find the tranpose of given matrix.

#include<stdio.h>
main()
{
int a[80][80],b[80][80],m,n,i,j;
clrscr();
printf("Enter the row and coloumn numbers\n ");
scanf("%d%d",&m,&n);
printf("Enter the elements of matrix\n");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n");
}
printf("The transpose of given matrix\n");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
printf("%d\t",a[j][i]);
}
printf("\n");
}
getch();
}

44. Program to generate multiplication group.

#include<stdio.h>
main()
{
int a[80][80],m,n,i,j;
clrscr();
printf("Enter the values of m,n\n ");
scanf("%d%d",&m,&n);
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
a[i][j]=i*j;
printf("%4d",a[i][j]);
}
printf("\n");
}
getch();
}

45. program to copy one string to another string.

#include<stdio.h>
#include<string.h>
main()
{
            char s1,s2;
clrscr();
printf("Enter the first string\n");
gets(s1);
printf("Enter the second string\n");
gets(s2);
strcat(s1,s2);
printf("The concadination of two strings %s",s1);
getch();
}

46. program to find the length of the string.

#include<stdio.h>
#include<string.h>
main()
{
char s1,s2;
int d1,d2;
clrscr();
printf("Enter the first string\n");
gets(s1);
printf("Enter the second string\n");
gets(s2);
d1=strlen(s1);
d2=strlen(s2);
printf("First string length = %d Second string lenth = %d",d1,d2);
getch();
}



47. program to compare two strings.

#include<stdio.h>
#include<string.h>
main()
{
            char s1,s2;
int x=0;
clrscr();
printf("Enter the first string\n");
gets(s1);
printf("Enter the second string\n");
gets(s2);
x=strcmp(s1,s2);
if(x==0)
printf("The two strings are equal");
if(x>0)
printf("The first string is greater than the second string"); }
else
printf("The Second string is greater than the first string"); }
getch();
}

48. program to find square root the given number.

#include<stdio.h>
#include<math.h>
main()
{
int n;
float d;
clrscr();
printf("Enter the value of n\n");
scanf("%d",&n);
d=sqrt(n);
printf("The square root of the given number = %f",d);
getch();
}

49. Program to find weather the given character is within the string or not.

#include<stdio.h>
main()
{
char ch,x[100];
int i,n;
clrscr();
printf("enter the string :");
scanf("%s",x);
printf("enter the charater :");
scanf("%s",&ch);
n=strlen(x);
for(i=0;i<=26;i++)
{
if(ch==x[i])
{
printf("the charater is found  ");
getch();
exit();
}
}
printf("The character is not found");
getch();
}

50. Program to find the gcd using recursion.

#include<stdio.h>
main()
{
int m,n,gcd;
clrscr();
printf("Enter the values od m and n\n");
scanf("%d%d",&m,&n);
gcd=gc(m,n);
printf("GCD of two numbers is = %d",gcd);
getch();
}
gc(int x,int y)
{
int r;
r=x-(x/y*y);
if(r==0)
return(y);
else
gc(y,r);
return;
}

51. program to find the factorial of the given number using recursion

#include<stdio.h>
main()
{
int n;
long int fact();
clrscr();
printf("Enter the value of n\n");
scanf("%d",&n);
printf("The factorial of %d is %ld",n,fact(n));
getch();
}
long int fact(int x)
{
if(x==0)
return(1);
else
return(x*fact(x-1));
}

52. program to generate fibonacci series using recursion.

#include<stdio.h>
main()
{
int n;
void fib();
clrscr();
printf("Number of terms to be generated\n");
scanf("%d",&n);
printf("The fibonacci series is\n");
fib(n);
getch();
}
void fib(int n)
{
static int f1=0,f2=1;
int temp;
if(n<2)
{
f1=0; f2=1;
}
else
{
fib(n-1);
temp=f2;
f2=f1+f2;
f1=temp;
}
printf("%5d",f1);
return;
}

53. program to find the sum of elements in an array.

#include<stdio.h>
main()
{
int n,a[80],i,sum=0;
clrscr();
printf("Enter the value of n");
scanf("%d",&n);
printf("Enter the elements in the list");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
sum+=a[i];
printf("The sum of the elements in the list= %d",sum);
getch();
}

54. program to convert binary number to decimal number.

#include<stdio.h>
main()
{
int bin,binary,decimal=0,digit,base=0;
clrscr();
printf("Input the binary number");
scanf("%d",&binary);
bin=binary;
while(binary)
{
digit=binary%10;
decimal+=digit<<base; /*shift one bit left*/
base+=1; binary/=10;
}
printf("Decimal equivalent of binary number %d= %d",bin,decimal);
getch();
}

55. program for nesting of macros.

#include<stdio.h>  
#define min(a,b) ((a)<(b))?(a):(b)) /* defining minimum of two*/
main()
{
int w,x,y,z,small;
clrscr();
printf("Enter any four numbers");
scanf("%d%d%d%d",&w,&x,&y,&z);
small= min(w,min(x,min(y,z)));
printf("minimum of the four numbers = %d",small);
getch();
}
           
56. program to sort the list of n names.

#include<stdio.h>
main()
{
  int i,n,j;
  char name[20][10],temp[10];
 clrscr();
  printf("enter no. of names to be sorted");
  scanf("%d",&n);
  printf("\nENTER THE NAMES u WISH TO SORT\n");
  for(i=0;i<n;i++)
   scanf("%s",name[i]);
  clrscr();
  printf("\n\n\n\n\t\tTHE NAMES AFTER SORTING \n");
  for(i=0;i<n-1;i++)
  {
for(j=i+1;j<n;j++)
{
             if(strcmp(name[i],name[j])>0)
            {
strcpy(temp,name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],temp);
            }
}
    }
   for(i=0;i<n;i++)
printf("\n\t\t\t\t%s",name[i]);
  getch();
}


57. program to find the substring of a given string.

#include<stdio.h>
#include<string.h>
main()
{
char mainstr[50],substr[50];
int count,pos,i,j,len,num;
clrscr();
printf("Enter the main string\n");
gets(mainstr);
puts(mainstr);
for(len=0;mainstr[len]!='\0';len++);
printf("\nIts'length is : %d",len);
printf("\nStarting position of the sub string");
scanf("%d",&pos);
printf("No.of characters i the sub string\n");
scanf("%d",&count);
if(pos<=0 || count<=0 || pos>len)
printf("\n\n Extracted string is empty\n");
else
{
if(pos+count>len)
{
printf("\n Characters to be extracted exceed length\n");
num=len-pos+1;
}
else
num=count; j=0;
for(i=--pos;i<=pos+num-1;i++)
{
substr[j]=mainstr[i];
j++;
}
printf("\n Substring is : %s ",substr);
}
 getch();
}
           
58. program to find the power of x .

#include<stdio.h>
main()
{
float x,power();
int n; clrscr();
printf("Enter the values of x and n");
scanf("%d%d",&x,&n);
printf("The n power of x = %f",power(x,n)); }
float power(float y,int m)
{
float fact;
if(m==0) return(1); else
fact=y*power(y,m-1);
return(fact);
}

59. program to construct a structure and print it.

#include<stdio.h>
struct st
{
char name[20],street[20],fname[20],town[20];
int hno;
}a;
main()
{
clrscr();
printf("\nEnter the  structer elements");
printf("\nEnter the name of the person: ");
scanf("%s",a.name);
printf("Enter the Father's name: ");
scanf("%s",a.fname);
printf("Enter the Street: ");
scanf("%s",a.street);
printf("Enter House Number: ");
scanf("%d",&a.hno);
printf("Enter Town: ");
scanf("%s",a.town);
clrscr();
printf("\n\n\n\t\t\tNAME           : %s",a.name);
printf("\n\t\t\tFATHER'S NAME  : %s",a.fname);
printf("\n\t\t\tHOUSE NUMBER   : %d",a.hno);
printf("\n\t\t\tSTREET         : %s",a.street);
printf("\n\t\t\tTOWN           : %s",a.town);
getch();
}

60. program to display details of a person using nested structures.

#include<stdio.h>
struct dob
{
int mm,yy,dd;
} d;
struct stud
{
char name[20],qfn[20],fname[20];
float tpn;
struct dob d;
}per;
main()
{
int i;
clrscr();
printf("\nENTER DETAILS OF A PERSON\n\n");
printf("Enter name         : ");
scanf("%s",per.name);
printf("Enter Father's name: ");
scanf("%s",per.fname);
printf("Enter Qualification: ");
scanf("%s",per.qfn);
printf("\nEnter DATE OF BIRTH\n");
printf("Enter Date: ");
scanf("%d",&per.d.dd);
printf("Enter Month: ");
scanf("%d",&per.d.mm);
printf("Enter Year: ");
scanf("%d",&per.d.yy);
printf("\nEnter Telephone: ");
scanf("%f",&per.tpn);
clrscr();
printf("\n\n\t\t\t  DETAILS OF PERSON \n");
for(i=0;i<80;i++) printf("|");
printf("\n\t\t\tNAME          : %s",per.name);
printf("\n\t\t\tFATHER'S NAME : %s",per.fname);
printf("\n\t\t\tQUALIFICATION : %s",per.qfn);
  printf("\n\t\t\tDATE OF BIRTH : %2d - %2d - %4d",per.d.dd,per.d.mm,per.d.yy);
printf("\n\t\t\tTELEPHONE NO. : %5.0f",per.tpn);
getch();
}

61. program to display details of a person for given telephone no.

#include<stdio.h>
struct stud
{
char name[20],qfn[20],fname[20],town[20];
            char street[20];
            float tpn;
}per[10];
main()
{
int i,n,j;
float stpn;
clrscr();
printf("\nENTER NO. OF PERSONS u WISH");
scanf("%d",&n);
for(i=0;i<n;i++)
{
            clrscr();
printf("\nENTER DETAILS OF A PERSON - %d\n\n",i+1);
            printf("Enter name         : ");
            scanf("%s",per[i].name);
            printf("Enter Father's name: ");
scanf("%s",per[i].fname);
            printf("Enter Qualification: ");
scanf("%s",per[i].qfn);
            printf("Enter Street: ");
            scanf("%s",per[i].street);
            printf("Enter Town: ");
            scanf("%s",per[i].town);
            printf("\nEnter Telephone: ");
            scanf("%f",&per[i].tpn);
     }
    printf("\nenter telephone no. U want to search: ");
    scanf("%f",&stpn);
    clrscr();
    for(i=0;i<n;i++)
     {
       if(stpn==per[i].tpn)
             {
               printf("\n\n\t\t\t   THE PERSON IS FOUND FOR T.P.No.%5.0f\n",stpn);
               for(j=0;j<80;j++) printf("þ");
               printf("\n\t\t\t NAME             : %s ",per[i].name);
               printf("\n\t\t\t FATHER'S NAME    : %s ",per[i].fname);
               printf("\n\t\t\t QUALIFICATION    : %s ",per[i].qfn);
               printf("\n\t\t\t STREET           : %s ",per[i].street);
               printf("\n\t\t\t TOWN             : %s ",per[i].town);
               break;
             }
            else  j=0;
            }
if(j==0) printf("\nNO PERSON WITH T.P.No %5.0f",stpn);
getch();
}

62. program to sort records of students based on roll numbers.

#include<stdio.h>
struct stud
{
char name[20],qfn[20],fname[20],town[20];
char street[20];
            int rn;
            float tpn;
}per[10],temp;
main()
{
int i,n,j;
clrscr();
printf("\nENTER NO. OF PERSONS u WISH");
scanf("%d",&n);
for(i=0;i<n;i++)
{
             clrscr();
             printf("\nENTER DETAILS OF A PERSON - %d\n\n",i+1);
 printf("Enter Roll No. : ");
             scanf("%d",&per[i].rn);
             printf("Enter name         : ");
             scanf("%s",per[i].name);
             printf("Enter Father's name: ");
             scanf("%s",per[i].fname);
             printf("Enter Qualification: ");
             scanf("%s",per[i].qfn);
             printf("Enter Street: ");
             scanf("%s",per[i].street);
             printf("Enter Town: ");
             scanf("%s",per[i].town);
             }
    clrscr();
for(i=0;i<n-1;i++)
{
            for(j=i+1;j<n;j++)
            {
                        if(per[i].rn>per[j].rn)
{
                  temp=per[i];
                  per[i]=per[j];
                  per[j]=temp;
}
              }
 }
for(i=0;i<n;i++)
{
clrscr();
printf("\n\t\t\t ROLL NUMBER      : %d",per[i].rn);
printf("\n\t\t\t NAME             : %s ",per[i].name);
printf("\n\t\t\t FATHER'S NAME    : %s ",per[i].fname);
printf("\n\t\t\t QUALIFICATION    : %s ",per[i].qfn);
printf("\n\t\t\t STREET           : %s ",per[i].street);
printf("\n\t\t\t TOWN             : %s ",per[i].town);
getch();
}
getch();
}

63. program to interchange two elements using pointers.

#include<stdio.h>
#include<alloc.h>
main()
{
int *a,*b;
clrscr();
a=(int *) malloc(sizeof(int));
b=(int *) malloc(sizeof(int));
printf("enter value of a: ");
scanf("%d",a);
printf("\nenter value of b: ");
scanf("%d",b);
*a=*a+*b;
*b=*a-*b;
*a=*a-*b;
printf("\nThe values are interchanged a=%d,b=%d",*a,*b);
getch();
}

64. program to find sum list of elements using pointers.

#include<stdio.h>
#include<alloc.h>
main()
{
int *a,i,n,sum=0;
clrscr();
printf("enter no.of elements U want to sum");
scanf("%d",&n);
a=(int *) malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
printf("Enter %d element",i+1);
scanf("%d",a+i);
sum+=*(a+i);
}
printf("\nThe sum of given list of elements is......%d",sum);
getch();
}

65. Program to generate multiplication group.

#include<stdio.h>
main()
{
int n,i;
clrscr();
printf("Enter the value of table u want to print\n ");
scanf("%d",&n);
for(i=1;i<=10;++i)
printf("\t%d  *  %d   =  %d \n",n,i,n*i);
getch();
}

66. program to find saddle pint in a matrix.

#include<stdio.h>
main()
{
int a[5][5],i,j,min,max,n,m,flag=1,p,q;
printf("enter order of matrix");
scanf("%d %d",&m,&n);
printf("enter elements of matrix");
clrscr();
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
            {
             gotoxy(5*j+5,i*2+2);
             scanf("%d",&a[i][j]);
             }
}
for(i=0;i<m;i++)
{
min=a[i][0];
p=i;q=0;
for(j=0;j<n;j++)
            {
              if(min>a[i][j])
               {
                 min=a[i][j];
                 p=i;
                 q=j;
                }
              }
            for(j=0;j<m;j++)
            {
               if(a[j][q]>a[p][q])
                flag=0;
 }
            if(flag)
printf("saddle point a[%d][%d]=%d\n",p+1,q+1,a[p][q]);
            else
             printf("NO saddle point in row %d\n",i+1);
            flag=1;
}
getch();
}

67. Program to print the following output .
                                                *
                                    *          *          *
                        *          *          *          *          *         
                                                                                                           
#include<stdio.h>
main()
{
int i,j,k,n,x=0;
clrscr();
printf("enter any no:");
scanf("%d",&n);
x=n+2;
for(i=1;i<=n;i++)
{
for(j=1;j<=x;j++)
printf(" ");
for(k=1;k<=2*i-1;k++)
printf("*");
x=x-1;
printf("\n");
}
getch(); }
68.  program to print the following output
                                    1
                                    1 2
                                    1 2 3................ 

#include<stdio.h>
main()
{
int i,j,n;
clrscr();
printf("Enter the value of n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("%d\t",j);
printf("\n");
}
getch();
}

69. program to print the following output
                                    1
                                    2 2
                                    3 3 3................ 

#include<stdio.h>
main()
{
int i,j,n;
clrscr();
printf("Enter the value of n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("%d\t",i);
printf("\n");
}
getch();
}

70.  program to print the following output
                                    11 12 13
                                    21 22 23
                                    31 32 33

#include<stdio.h>
main()
{
int i,j;
clrscr();
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
printf("%d%d\t",i,j);
printf("\n");
}
getch();
}

71. program to print the following output
                                    1 2 3 ......
                                    1 2
                                    1      

#include<stdio.h>
main()
{
int i,j,n;
clrscr();
printf("Enter the no.of lines");
scanf("%d",&n);
for(i=n;i>0;i--)
{
for(j=1;j<=i;j++)
printf("%d\t",j);
printf("\n");
}
getch();
}

72. program to print the following output
                                    1
                                    2 3
                                    4 5 6
                                    7 8 9 10      

#include<stdio.h>
main()
{
int i,j,n,k=0;
clrscr();
printf("Enter the no.of lines");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
k+=1;
printf("%d\t",k);
}
printf("\n");
}
getch();
}

73. program to print the following output
                                    1
                                    3 3
                                    5 5 5...  

#include<stdio.h>
main()
{
int n,i,j,sum=1;
clrscr();
printf("Enter the no.of lines");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("%d\t",sum);
printf("\n");
sum+=2;
}
getch();
}

74. program for pascal triangle

 #include<stdio.h>
 main()
 {
int binom,p,q,r,x;
binom=1;
q=0;
clrscr();
printf("INPUT THE NO. OF ROWS: ");
scanf("%d",&p);
printf("%d\n",p);
printf("Pascals triangle : \n");
while(q<p)
{
for(r=40-3*q;r>0;--r)
printf(" ");
for(x=0;x<=q;++x)
{
if((x==0) || (q==0))
binom=1;
else
binom=(binom*(q-x+1))/x;
printf("%6d",binom);
   }
   printf("\n");
   ++q;
}
getch();
}

75. program to merge two arrays.

  #include<stdio.h>
    main()
    {
            int a[10],b[10],c[20],i,j,n1,n2,n;
clrscr();
printf("enter no. of elements of array-1");
scanf("%d",&n1);
printf("\nenter no. of elements of array-2");
scanf("%d",&n2);
printf("\nenter array-1 elements\n");
for(i=0;i<n1;i++)
scanf("%d",&a[i]);
printf("enter array-2 elements\n");
for(j=0;j<n2;j++)
scanf("%d",&b[j]);
n=n1+n2;
for(i=0;i<n;i++)
{
if(i<n1)
{
            c[i]=a[i];
j=0;
            }
            else
            {
c[i]=b[j];
j++;
             }
}
printf("\nThe two arrays are merged");
printf("\nthe elements after merging ........\n");
for(i=0;i<n;i++)
     printf("%d\t",c[i]);
getch();
}



76. program to copy strings using pointers.

#include<stdio.h>
 main()
{
char s[80],t[80];
printf("enter first string: ");
gets(s);
printf("enter second string: ");
gets(t);
strcpy(s,t);
printf("\nafter the string=%s",s);
getch();
}
strcpy(char x,char y)
{
            while(*y != '\0')
{
*x=*y;
 x++;
   y++; 
            }         
 *x='\0';
}

77. program to concatenation of two strings using pointers.

   #include<stdio.h>
   #include<malloc.h>
   #define length 40
   main()
   {
char *s1,*s2,*s3,c;
int i,j,k;
clrscr();
s1=(char *) malloc(length*sizeof(char));
s2=(char *) malloc(length*sizeof(char));
s3=(char *) malloc(length*sizeof(char));
printf("\nenter string-1: ");
scanf("%s",s1);
printf("\nenter string-2: ");
scanf("%s",s2);
i=0;
while(*(s1+i) != '\0')
{
*(s3+i) =*(s1+i);
            i++;
}
k=0;
while(*(s2+k) != '\0')
{
*(s3+i+k)=*(s2+k);
            k++;
}
printf("\nConcatenated string is........");
printf("%s\n",s3);
getch();
}

78. program to print system date and time.

#include<stdio.h>
#include<dos.h>
struct date t;
struct time k;
main()
{
clrscr();
while(!kbhit())
{
getdate(&t);
gettime(&k);
gotoxy(12,3);
printf("Date : %d/%d/%d\t",t.da_day,t.da_mon,t.da_year);
gotoxy(12,50);
printf("Time - %d:%d:%d",k.ti_hour,k.ti_min,k.ti_sec);
}
getch();
}

79. Program to find the roots of the quadratic equation.

 # include<stdio.h>
main()
{
int root1,root2,a,b,c,d;
clrscr();
printf("enter the values of a,b,c\n");
scanf("%d%d%d",&a,&b,&c);
            d=b*b-4*a*c;
if(d==0)
{
printf("the roots are equal\n");
root1=-b/2*a;
root2=-b/2*a;
printf("root1=%d\nroot2=%d\n",root1,root2);
}
else
{
if(d>0)
{
printf("the roots are real and differant\n");
root1=-b+sqrt(d)/2*a;
root2=-b-sqrt(d)/2*a;
printf("root1=%d\nroot2=%d\n",root1,root2);
                        }
else
printf("the roots are imaginary");
}
           
80. Program to perform arithmetic operations using switch statement

#include<stdio.h>
main()
{
int a,b,d,a1;
char c;
clrscr();
printf("enter a,b no:");
scanf("%d %d",&a,&b);
printf("enter the value of +,-,*,/ \n");
scanf("%s",&c);
a1=c;
switch(c)
{
case '+'             :           d=a+b;
             break;
case '-'             :           d=a-b;
             break;
case '*'             :            d=a*b;
             break;
case '/'              :           d=a/b;
             break;
default              :           d=a%b;
}
printf("the result of a and b is= %d %c %d=%d",a,a1,b,d);
getch();
}

81. Program to arrange the elements in bubble sort.

# include <stdio.h>
main()
{
int a[80],n,i,j,temp;
clrscr();
printf("enter the no. of elements in the list");
scanf("%d",&n);
printf("enter the elements in the list\n");
for (i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("the buble sort is=\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
getch();
}

82. program to find weather the given number is amstrong or not.

#include<stdio.h>
main()
{
int n,i,d,s=0,k;
clrscr();
printf("Enter the value of n\n");
scanf("%d",&n);
k=n;
while(n!=0)
{
d=n%10;
s=s+(d*d*d);
n/=10;
}
if(s==k)
printf("The given number is amstrong");
else
printf("The given number is not a amstrong");
getch();
}

83. program to print the calender from 1900 onwards.

void call();
main()
{
int i,y=1900,t=2,h=0,row=7,m;
clrscr();
call();
for(y=1900;y<=3000;++y)
{
for(m=1;m<=12;++m)
{
if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
h=31;
else
if(m==4||m==6||m==9||m==11)
h=30;
else
{
if(y%4==0 && y%100!=0)
h=29;
else
h=28;
}
gotoxy(15,3);
printf("year=%d   month=%d",y,m);
for(i=1;i<=h;++i)
{
gotoxy(10+5*(t-1),row);
printf("%d",i);
++t;
if(t==8)
{
t=1;
row=row+2;
}
}
getch();
row=7;
call();
}
}
}
void call()
{
clrscr();
gotoxy(10,5);
printf("SUN");
gotoxy(15,5);
printf("MON");
gotoxy(20,5);
printf("TUE");
gotoxy(25,5);
printf("WED");
gotoxy(30,5);
printf("THU");
gotoxy(35,5);
printf("FRI");
gotoxy(40,5);
printf("SAT");
}

84. program to 'getc' and putc' functions.

#include<stdio.h>
main()
            {
FILE *fp;
char c;
clrscr();
fp=fopen("TEXT","w");
printf("Enter text - Terminate with ctrl+z\n");
while((c=getchar())!=EOF)
{
putc(c,fp);
                        }
fclose(fp);
printf("\nDisplaying text from file......\n\n");
fp=fopen("TEXT","r");
while((c=getc(fp))!=EOF)
            {
                        printf("%c",c);
            }
fclose(fp);
getch();
}

85. program to count no.of charectors,no of tabs,no.of spaces,no.of new lines.

# include<stdio.h>
main()
{
FILE *fp;
char ch;
int nt=0,nl=0,nc=0,nb=0;
fp=fopen("shiva.c","r");
clrscr();
while(1)
{
ch=getc(fp);
if (ch==EOF)
break;
nc++;
if(ch== ' ')
++nb;
if(ch== '\n')
++nl;
if(ch== '\t')
++nt;
}
fclose(fp);
printf("the no of charectors=%d\n",nc);
printf("the no of blankspaces=%d\n",nb);
printf("the no of new lines=%d\n",nl);
printf("the no of tabspaces=%d\n",nt);
}

86. program to create a file and enter data into it and display data on screen.

#include<stdio.h>
main()
{
FILE *fp1;
int n,i,num;
fp1=fopen("DATA.DAT" ,"w");
printf("enter the no. of file componants\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&num);
putw(num,fp1);
}
fclose(fp1);
fp1=fopen("DATA.DAT","r");
while(getw(fp1)!=FEOF)
{
num=getw(fp1);
printf("the file componant is =%d\n",num);
}
fclose(fp1);
   }

87. program to create a file named as “DATA” having file components belongs  to the integer type ,to read file components from the file if it is odd number put into file name “ODD”,otherwise put into file name “EVEN”.

# include<stdio.h>
main()
{
FILE *fp1,*fp2,*fp3;
int n,i,num;
clrscr();
fp1=fopen("data","w");
printf("enter the no of elements in the file\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("enter the number\n");
scanf("%d",&num);      
putw(num,fp1);
}
fclose(fp1);
fp1=fopen("data","r");
fp2=fopen("odd","w");
fp3=fopen("even","w");
while((num=getw(fp1))!=EOF)
{
if(num%2==0)
putw(num,fp3);
else
putw(num,fp2);
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
fp1=fopen("data","r");
fp2=fopen("odd","r");
fp3=fopen("even","r");
while((num=getw(fp1))!=EOF)
printf("\n%d",num);
while((num=getw(fp3))!=EOF)
printf("\n%d\n",num);
while((num=getw(fp2))!=EOF)
printf("\n%d",num);
fclose(fp1);
fclose(fp2);
fclose(fp3);
getch();
}

88. program to print the text in different fonts.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
main()
{
int d=DETECT,m,i;
initgraph(&d,&m,"");
while(!kbhit())
{
for(i=0;i<10;i++)
{
setcolor(i);
settextstyle(i,0,5);
outtextxy(200,100,"Shiva");
delay(4000);
cleardevice();
}  
}
getch();
}

89.  program to print olympic symbols.

#include<stdio.h>
#include<graphics.h>
main()
{
int i,j;
clrscr();
detectgraph(&i,&j);
initgraph(&i,&j," ");
for(i=160;i<170;i++)
circle(i,100,90);
for(i=270;i<280;i++)
circle(i,100,90);
for(i=380;i<390;i++)
circle(i,100,90);
for(i=190;i<200;i++)
circle(i,190,90);
for(i=350;i<360;i++)
circle(i,190,90);
settextstyle(4,HORIZ_DIR,9);
outtextxy(30,300,"OLYMPICS");
getch();
}

90. Program for text animation.

#include <graphics.h>
#include <stdio.h>
#include <conio.h>
main()
{
int gm,gd=DETECT,i,j,k;
clrscr();
initgraph(&gd,&gm,"");
k=1;
while(!kbhit())
{
for(i=0,j=0;i<=600 && j<=400 ;i+=2,j+=2)
{
settextstyle(1,0,7);
outtextxy(640-i,480-j,"SHIVA");
setcolor(k);
}
delay(200);
for(i=0,j=0;i<=600 && j<=400 ;i+=2,j+=2)
{
settextstyle(1,0,7);
outtextxy(640-i-2,480-j-2,"SHIVA");
setcolor(BLACK);
}
setcolor(k+1);
outtextxy(640-i,480-j,"SHIVA");
k++;
}
getch();
}

91. Program to generate love symbol animation.

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
main()
{
int d=DETECT,m,i;
initgraph(&d,&m,"");
while(!kbhit())
{
for(i=0;i<=300;i+=10)
{
setcolor(i);
symbol(i,i-80);
setcolor(i+1);
symbol(600-i,i-80);
setcolor(i+2);
symbol(i,520-i);
setcolor(i+3);
symbol(600-i,520-i);
setcolor(i+4);
symbol(300,220);
delay(2000);
if(i==300)
continue;
setcolor(0);
symbol(i,i-80);
symbol(600-i,i-80);
symbol(i,520-i);
symbol(600-i,520-i);
}
for(i=0;i<=200;i++)
{
setcolor(i);
symbol(300,220);
delay(200);         
}
for(i=0;i<=300;i+=10)
{
setcolor(i);
symbol(300-i,220-i);
setcolor(i+1);
symbol(300+i,220-i);
setcolor(i+2);
symbol(300-i,220+i);
setcolor(i+3);
symbol(300+i,220+i);
setcolor(i+4);
symbol(300,220);
delay(2000);
if(i==300)
continue;
setcolor(0);
symbol(300-i,220-i);
symbol(300+i,220-i);
symbol(300-i,220+i);
symbol(300+i,220+i);
}
}
}
symbol(int x,int y)
{
arc(x,y,0,180,20);
arc(x+40,y,0,180,20);
line(x-20,y,x+20,y+50);
line(x+20,y+50,x+60,y);
}

92. Program to form Indian Titanic.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void *ship;
main()
{
int d=DETECT,m,i;
initgraph(&d,&m,"");
while(!kbhit())
{
boat();
moveimage();
}
getch();
}
shiva()
{
int i;
for(i=0;i<=680;i++)
{
setcolor(5);
line(680-i,400,780-i,400);
line(660-i,420,760-i,420);
line(640-i,440,740-i,440);
line(620-i,460,720-i,460);
line(600-i,480,700-i,480);
setcolor(0);
line(680-i,400,780-i,400);
line(660-i,420,760-i,420);
line(640-i,440,740-i,440);
line(620-i,460,720-i,460);
line(600-i,480,700-i,480);
}
}
boat()
{
int i=0;
setcolor(WHITE);
arc(440,350,180,270,40);
line(430,390,540,390);
line(430,388,546,388);
line(430,389,545,389);
arc(540,350,270,360,40);
line(400,357,580,357);
line(400,353,580,353);
line(400,350,580,350);
line(411,378,570,378);
line(415,380,568,380);
line(417,383,565,383);
line(419,386,562,386);
line(405,371,425,371);
line(402,360,425,360);
line(402,363,425,363);
line(405,366,425,366);
line(407,368,425,368);
line(409,374,425,374);
line(560,360,578,360);
line(560,363,576,363);
line(560,366,577,366);
line(560,368,575,368);
line(560,371,574,371);
line(560,374,574,374);
setcolor(9);
settextstyle(4,0,2);
outtextxy(430,355,"Indian Titanic");
setfillstyle(7,i);
setcolor(WHITE);
line(400,355,580,355);
arc(440,350,90,180,18);
line(440,332,560,332);
arc(555,350,0,90,18);
setcolor(i);
outtextxy(490,330,"Shiva");
bar(492,336,504,344);
bar(516,336,528,344);
i++;
shiva();
setcolor(WHITE);
line(400,310,400,350);
setfillstyle(1,RED);
bar(380,310,400,315);
setfillstyle(1,WHITE);
shiva();
bar(380,315,400,320);
setfillstyle(7,8);
fillellipse(390,317,3,3);
setfillstyle(1,GREEN);
bar(380,320,400,325);
ship=malloc(imagesize(350,300,620,405));
getimage(350,300,620,405,ship);
}
moveimage()
{
int i;
for(i=0;i<=200;i++)
{
mm();
putimage(350-i,300,ship,XOR_PUT);
shiva();
cleardevice();
}
}
love()
{
setcolor(BLUE);
arc(200,170,0,180,20);
arc(240,170,0,180,20);
line(180,170,220,220);
line(260,170,220,220);
}
 mm()
{
setcolor(RED);
settextstyle(4,0,5);
outtextxy(100,60,"I");
love();
setcolor(RED);
outtextxy(400,200,"INDIA");
settextstyle(1,0,2);
outtextxy(195,162,"Shiva");
}

93. Execute the program and see what will happen.

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
 main()
{
int d=DETECT,m,i=1,j=1,x=400,k=0;
initgraph(&d,&m,"");
while(!kbhit())
{
setlinestyle(2,0,2);
setcolor(j);
for(i=0;i<=200;i++)
{
ellipse(300-i,400-i,200-i,160+i,218-i,225-i);
ellipse(300-i,187,-110+i,-20+i,240-i,212-i);
ellipse(300-i,345-i,70+i,-110+i,220-i,229-i);
ellipse(300-i,-73+i,200-i,160+i,212-i,212-i);
ellipse(400-i,410-i,200-i,160+i,215-i,215-i);
ellipse(425-i,375-i,45+i,-80+i,230-i,249-i);
line(20+i,-75+i,60+i,300-i);
line(i,-80+i,20+i,325-i);
if(i==100)
{
settextstyle(5,0,6);
for(k=0;k<=100;k++)
{
setcolor(k);
outtextxy(400,400,"What's it");
delay(900);
}
delay(900);
x=4000;
setcolor(j);
}
if(i==200)
{
delay(900);
x=400;
continue;
}
delay(900);
cleardevice();
}
j++;
delay(100000);
}
getch();
}



94. Program to show progress bar.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
main()
{
int d=DETECT,m,i,k;
initgraph(&d,&m,"");
setcolor(4);
setfillstyle(1,CYAN);
bar3d(200,300,450,350,0,0);
setfillstyle(1,MAGENTA);
settextstyle(10,0,6);
outtextxy(100,50,"Loading..");
bar(250,315,400,335);
settextstyle(5,0,1);
outtextxy(270,290,"Processing...");
for(i=0;i<=100;i++)
{
textbackground(2);
setfillstyle(1,1);
bar(250,315,250+(i*1.5),335);
gotoxy(40,21);
printf("%d%",i);
delay(1000);
}
getch();
}

95. program to generate a scrolling marquee.

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
main()
{
int gm,gd=DETECT;
int x=640,y=210,j=1;
initgraph(&gd,&gm,"");
settextstyle(7,0,8);
while(!kbhit())
{
outtextxy(x,y,"WELCOME TO MY PERSONAL BOOK OF C");
setcolor(LIGHTRED);
outtextxy(x-1,y,"WELCOME TO MY PERSONAL BOOK OF C");
setcolor(BLACK);
if(x<=-1285)
{
cleardevice();
x=640;
}
x=x-1;
}
return 0;
}

96. Program to generate ETV symbol.

 #include<stdio.h>
#include<conio.h>
#include<graphics.h>
main()
{
int i,m,d,j=1;
detectgraph(&d,&m);
initgraph(&d,&m,"");
while(!kbhit())
{
setcolor(j);
for(i=15;i<=20;i++)
{
line(570,47,475,45+i);
line(510+i,75-i,510+i,110-i);
arc(510+i,52,0,90,7);
line(517+i,50,525+i,80);
line(525+i,80,540+i,50);
ellipse(500,60,0,360,i,27);
line(500,33,530,5+i);
line(500,33,490,43-i);
}
delay(10000);
j++;
}
getch();
}

97. Program of a exercising man.

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
main()
{
int d,m,i,j;
detectgraph(&d,&m);
initgraph(&d,&m,"");
circle(400,200,20);
line(400,195,395,205);
line(395,205,400,205);
ellipse(400,212,0,360,6,3);
setcolor(WHITE);
circle(400,200,20);
circle(393,193,3);
circle(406,193,3);
line(400,195,395,205);
line(395,205,400,205);
while(!kbhit())
{
for(i=0;i<=50;i++)
{
setcolor(WHITE);
circle(400,200,20);
setcolor(i);
circle(393,193,3);
circle(406,193,3);
setcolor(WHITE);
line(400,195,395-i/7,205);
line(395-i/7,205,400,205);
setcolor(i);
ellipse(400,212,0,360,i/8,3);
setcolor(WHITE);
line(400,220,400,300);
line(400,240,340,260-i);
line(400,240,460,260-i);
line(400,300,360-i,420-i);
line(400,300,440+i,420-i);
delay(400);
setcolor(BLACK);
line(400,195,395-i/7,205);
line(395-i/7,205,400,205);
ellipse(400,212,0,360,i/8,3);
line(400,220,400,300);
line(400,240,340,260-i);
line(400,240,460,260-i);
line(400,300,360-i,420-i);
line(400,300,440+i,420-i);
}
for(i=0;i<=50;i++)
{
setcolor(WHITE);
circle(400,200,20);
setcolor(i);
circle(393,193,3);
circle(406,193,3);
setcolor(WHITE);
line(400,195,387+i/7,205);
line(387+i/7,205,400,205);
setcolor(i);
ellipse(400,212,0,360,i/8,3);
setcolor(WHITE);
line(400,220,400,300);
line(400,240,340,210+i);
line(400,240,460,210+i);
line(400,300,310+i,370+i);
line(400,300,490-i,370+i);
delay(400);
setcolor(BLACK);
line(400,195,387+(i/7),205);
line(387+i/7,205,400,205);
ellipse(400,212,0,360,i/8,3);
line(400,220,400,300);
line(400,240,340,210+i);
line(400,240,460,210+i);
line(400,300,310+i,370+i);
line(400,300,490-i,370+i);
}
}
getch();
}

98. program for deviation and combination of text.

#include<bios.h>
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
main()
{
int d=DETECT,m,i;
initgraph(&d,&m,"");
while(!kbhit())
{
for(i=0;i<=200;i++)
{
settextstyle(1,0,4);
setcolor(YELLOW);
outtextxy(100+i,i,"SHIVA");
outtextxy(500-i,i,"SHIVA");
outtextxy(100+i,400-i,"SHIVA");
outtextxy(500-i,400-i,"SHIVA");
outtextxy(300,i,"SHIVA");
outtextxy(300,400-i,"SHIVA");
outtextxy(100+i,200,"SHIVA");
outtextxy(500-i,200,"SHIVA");
if(i==200)
delay(100000);
delay(10);
setcolor(0);
outtextxy(100+i,i,"SHIVA");
outtextxy(500-i,i,"SHIVA");
outtextxy(100+i,400-i,"SHIVA");
outtextxy(500-i,400-i,"SHIVA");
outtextxy(300,i,"SHIVA");
outtextxy(300,400-i,"SHIVA");
outtextxy(100+i,200,"SHIVA");
outtextxy(500-i,200,"SHIVA");
}
for(i=0;i<=200;i++)
{
settextstyle(1,0,4);
setcolor(BROWN);
outtextxy(300-i,200-i,"SHIVA");
outtextxy(300+i,200-i,"SHIVA");
outtextxy(300-i,200+i,"SHIVA");
outtextxy(300+i,200+i,"SHIVA");
outtextxy(300,200-i,"SHIVA");
outtextxy(300,200+i,"SHIVA");
outtextxy(300-i,200,"SHIVA");
outtextxy(300+i,200,"SHIVA");
setcolor(0);
outtextxy(300-i,200-i,"SHIVA");
outtextxy(300+i,200-i,"SHIVA");
outtextxy(300-i,200+i,"SHIVA");
outtextxy(300+i,200+i,"SHIVA");
outtextxy(300,200-i,"SHIVA");
outtextxy(300,200+i,"SHIVA");
outtextxy(300-i,200,"SHIVA");
outtextxy(300+i,200,"SHIVA");
}
}
getch();
}

99. program to intiate mouse and print text on left click.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
main()
{
int d=DETECT,x,y,m,buttons,ox,oy,i=0;
union REGS regs;
initgraph(&d,&m,"");
setcolor(4);
regs.x.ax=0;
int86(0x33,&regs,&regs);
if(regs.x.ax==0)
{
outtextxy(100,100,"Mouse not found");
delay(10000);
theend();
}
regs.x.ax=1;
int86(0x33,&regs,&regs);
regs.x.ax=15; /*mouse ratio */
regs.x.cx=1; /* pixel make more distant */
regs.x.dx=1;
int86(0x33,&regs,&regs);
x=0;
y=0;
do
{
ox=x;
oy=y;
regs.x.ax=3;
int86(0x33,&regs,&regs);
buttons =regs.x.bx &3;
if(regs.x.bx &1) /* left button*/
{
ox=regs.x.cx;
oy=regs.x.dx;
setcolor(i);
settextstyle(5,0,5);
outtextxy(ox,oy-50,"Shiva");
}
i++;
if(i==10)
i=0;
}while(buttons!=3);
cleardevice();
int86(0x33,&regs,&regs);
setcolor(5);
outtextxy(100,100,"Have a mice day");
getch();
regs.x.ax=2;
closegraph();
}



100. Program to reboot the system.

            main()
            {
                        void interrupt (*old)( );
                        old = 0xFFFF0000;
                        (*old)();
            }
           

No comments:

Post a Comment