Sie sind auf Seite 1von 9

Computer science practical programs:

I. Simple programs :-
1. Finding largest and smallest using if and if-else.
2. Solution for Quadratic Equation (all cases).
3. Finding area of different shapes using switch statement.
4. Sum of series:
a. Sine.
b. Cosine.
c. ex.
5. Ascending and Descending order of numbers in arrays.
6. Shorting of names in alphabetic order.
II. Advanced programs:-
7. Matrix operations
a) Addition.
b) Subtraction.
c) Multiplication
.
8. Using recursive function
a) Finding factorial of number.
b) Generating Fibonacci series.

9. String manipulations without using string function


a) String length.
b) String comparison.
c) String copy.
10. Using function pointers
a) Palindrome checking.
b) Counting characters, words and line.
11. Numerical methods
a) Bisection.
b) Newton-Raphson Method.
12. Creating and processing of sequential files use structures
for Record Description a) Payroll. b) Mark list preparation.
C program for largest and smallest number:
#include<stdio.h>
#include<conio.h>
void main()
{
int A,B,C;
clrscr();
printf("\t\t PROGRAM FOR FIND THE LARGEST NUMBER AMONG THREE
NUMBERS\N");
printf("\n ENTER THREE NUMBERS : - \n");
printf("\n A= ");
scanf("%d",&A);
printf("\n B=");
scanf("%d", &B);
printf("\n C=");
scanf("%d", &C);
if(A>B)
{
if(A>C)
{
printf("\n GRATEST NUMBER IS A= %d ",A);

}
else if(C>A)
{
printf("\n GREATEST NUMBER IS C= %d",C);
}
}
}
else if(B>C)
{
if(B>A)
{
printf("\n GRATEST NUMBER IS B = %d", B);
}
}
else if(C>A)
}
else
{
printf("\n GREATEST NUMBERS IS C=%d", C);
}
}
esle if(A==B && B==C)
{
{
printf("\n ALL ARE EQUAL A = B = C = %d", C);
getch();}
C program for finding solution for Quadratic eqation(all cases) :
C program for finding area of different shapes:
# include<stdio.h>
# include<conio.h>
int ch, r, a, h, d, l;
float Ac, Ar, At;
Void main ()
{
clrscr();
printf(“\n press1,area of circle”);
printf(“\n press2,area of rectangle”);
printf(“\n press3,area of triangle”);
printf(“\n enter your choice”);
scanf(“%d”,&amp;ch);
switch(ch)
{
case 1: printf(“\n enter values to find area of circle”);
scanf (“%d”,&amp;r);
Ac = 3.14*r*r;
printf(“\n area of circle is %f”,Ac);
break;
case 2: printf(“\n enter values to find area of rectangle “);
scanf(“%d%d”,&amp;a,&amp;h);
Ar= a*h;
printf(“\n area of rectangle is %f”,Ar);
break;
case 3: printf(“\n enter values to find volume of cylinder”);
scanf(“%d%d”,&amp;d,&amp;l);
At = 0.5*d*l;
printf(“\n area of triangle is %f”,At);
break;
DEFAULT: printf(“\n enter the proper choice”);
}
getch();
}
c program for sum of sine series:
#include<stdio.h>
#include<math.h>
void main()
{
     int i = 2, n, s = 1, x, pwr = 1, dr;
     float nr = 1, x1, sum;
     clrscr();
     printf("\n\n\t ENTER THE ANGLE...: ");
     scanf("%d", &x);
     x1 = 3.142 * (x / 180.0);
     sum = x1;
     printf("\n\t ENTER THE NUMBER OF TERMS...: ");
     scanf("%d", &n);
     while(i <= n)
     {
         pwr = pwr + 2;
         dr = dr * pwr * (pwr - 1);
         sum = sum + (nr / dr) * s;
         s = s * (-1);
         nr = nr * x1 * x1;
         i+= 2;
     }
     printf("\n\t THE SUM OF THE SINE SERIES IS..: %0.3f",sum);
     getch();
}
C program for sum of cosine series:
#include<stdio.h>
#include<math.h>
void main()
{
      float pow = 2.0, nr, dr = 1.0, x1, sum;
      int i = 1,n,s = -1,x;
      clrscr();
      printf("\n\n\t ENTER THE ANGLE...: ");
      scanf("%d", &x);
      x1 = 3.142 * (x / 180.0);
      sum = 1.0;
      nr = x1*x1;
      printf("\n\t ENTER THE NUMBER OF TERMS...: ");
      scanf("%d",&n);
      while(i<=n)
      {
            dr = dr * pow * (pow - 1.0);
            sum = sum + (nr / (dr * s));
            s = s * (-1);
            pow = pow + 2.0;
            nr = nr * x1 * x1;
            i++;
      }
      printf("\n\t THE SUM OF THE COS SERIES IS..: %0.3f", sum);
      getch();
}

Das könnte Ihnen auch gefallen