PST LAB Mannual
PST LAB Mannual
#include<stdio.h>
int main()
{
int rad;
float PI = 3.14, area, ci;
ci = 2 * PI * rad;
printf("\nCircumference : %f ", ci);
return (0);
}
2. Write a program to read three numbers and find the biggest of three.
#include <stdio.h>
void main()
{
int n1, n2, n3;
printf("Enter three numbers: ");
scanf("%d %d %d", &n1, &n2, &n3);
int main()
{
int num;
printf("Enter the number\n");
scanf("%d",&num);
int count=0;
for(int i=2;i<num;i++) //Check for factors
{
if(num%i==0)
count++;
}
if(count!=0) //Check whether Prime or not
{
printf("Not a prime number\n");
}
else
{
printf("Prime number\n");
}
return 0;
}
4. Write a program to read a number, find the sum of the digits, reverse the
number and check it for palindrome
# include<stdio.h>
# include<conio.h>
void main()
{
intnum,x;
int sum=0,rev=0,rem;
clrscr();
printf("\n Enter a number : ");
scanf("%d",&num);
x=num;
while(num>0)
{
rem=num%10;
sum=sum+rem;
rev=rev*10+rem;
num=num/10;
}
printf("\n Sum of digits = %d",sum);
printf("\n Reversed number = %d",rev);
if(x==rev)
printf("\n Number is a Palindrome");
else
printf("\n Number is not a Palindrome");
getch();
}
#include<stdio.h>
int main()
{
float percentage;
printf(“Enter the percentage of the students \n”);
scanf(“%f”,&percentage);
if(percentage>=75)
printf(“Scored First class with distinction”);
else
if(percentage>=50)
printf(“Scored Second class”);
else
if(percentage>=35)
printf(“Scored Third class”);
else
printf(“Sorry, failed, you need to improve”);
}
7. Write a c program to find the roots of a quadratic equation
#include <math.h>
#include <stdio.h>
int main() {
double a, b, c, discriminant, root1, root2, realPart, imagPart;
printf("Enter coefficients a, b and c: ");
scanf("%1f %lf %lf", &a, &b, &c);
discriminant = b * b - 4 * a * c;
// condition for real and different roots
if (discriminant > 0)
{
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("root1 = %.2lf and root2 = %.2lf", root1, root2);
}
// condition for real and equal roots
else if (discriminant == 0)
{
root1 = root2 = -b / (2 * a);
printf("root1 = root2 = %.2lf;", root1);
}
// if roots are not real
else
{
realPart = -b / (2 * a);
imagPart = sqrt(-discriminant) / (2 * a);
printf("root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi", realPart, imagPart,
realPart, imagPart);
}
return 0;
}
8.Writea program to read marks scored by n students and find
the average of marks
#include <stdio.h>
int main()
{
int n, i;
floatmarks[30], sum = 0, avg;
printf("Enter the numbers of elements: ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("%d. Enter number: ", i + 1);
scanf("%f", &marks[i]);
sum=sum+ marks[i];
}
avg = sum / n;
printf("Average = %.2f", avg);
return 0;
}
9.write a C program to to remove Duplicate Element in a single
dimensional Array
#include <stdio.h>
int main ()
{
int a[50], i, j, k, n;
printf (" Define the number of elements in an array: ");
scanf (" %d", &n);
printf (" \n Enter %d elements of an array: \n ", n);
/*
finding the SUM of the two matrices
and storing in another matrix sum of the same size
*/
for(c = 0; c < m; c++)
for(d = 0; d < n; d++)
sum[c][d] = first[c][d] + second[c][d];
/*
finding the DIFFERENCE of the two matrices
and storing in another matrix difference of the same size
*/
for(c = 0; c < m; c++)
for(d = 0; d < n; d++)
diff[c][d] = first[c][d] - second[c][d];