Computer Science Practical Programs: I. Simple Programs
Computer Science Practical Programs: I. Simple Programs
Computer Science Practical Programs: I. Simple 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.
}
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”,&ch);
switch(ch)
{
case 1: printf(“\n enter values to find area of circle”);
scanf (“%d”,&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”,&a,&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”,&d,&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();
}