PSP Lab Record
PSP Lab Record
Date:
Aim
interest
Algorithm:
Step 1: Start
Step 2: Get P, n, r value
Step3: Calculate SI=(p*n*r)/100
Step 4: Display S
Step 5: Stop
Flowchart:
Pseudocode :
BEGIN
READ P, n, r
CALCULATE S
SI=(p*n*r)/100
DISPLAY SI
END
Result
Thus, the above program has been successfully compiled and the output has been
verified.
Ex No: 02 Program to Perform Arithmetic Operations
Date:
Aim
Program
#include<stdio.h>
void main()
{
inta,b;
printf(“enter a and b value”);
scanf(“%d%d”,&a,&b);
printf(“Addition=%d\n”,a+b);
printf(“Subtraction=%d\n”,a-b);
printf(“Multiplication=%d\n”,a*b):
printf(“Division=%d\n”,a/b);
printf(“Reminder=%d\n”,a%b);
}
Input &Output:
Result
Thus the above program has been successfully compiled and the output has been
verified.
Ex No: 03 Program to find the area of the circle
Date:
Aim
Program
#include<stdio.h>
void main()
{
float area, r;
scanf(“%f”,&r);
area=3.14*r*r;
printf(“%f”,area);
}
Input &Output
Enter the value 1
314.0000
Result
Thus the above program has been successfully compiled and the output has been
verified.
Ex No: 04 Program to Check whether a given number is Positive or Negative
or Zero using if statement
Date:
Aim
Program
#include <stdio.h>
#include <conio.h>
void main()
{
int number;
clrscr();
printf("Enter a number\n");
scanf ("%d", &number);
printf(" \n\n\nFinding positive,Negative and Zero \n");
printf("_____________________________________ \n");
if (number > 0)
printf ("%d is a Positive Number\n", number);
else if(number<0)
printf ("%d is a Negative Number\n", number);
else
printf ("%d is a Zero \n", number);
getch();
}
Enter a number
9
Finding positive,Negative and Zero
9 is a Positive Number
Enter a number
-9
Finding positive,Negative and Zero
-9 is a Negative Number
Enter a number
0
Finding positive,Negative and Zero
0 is a Zero Number
Result
Thus the above program has been successfully compiled and the output has been
verified.
Ex No: 05 Program to Check Vowels or Consonant Using SwitchCase
Date:
Aim
To check whether the given character is a Vowel or a Consonant Using Switch Case
Program
#include<stdio.h>
void main()
{
char ch;
clrscr();
printf("\n Enter any character:");
scanf("%c",&ch);
switch(ch)
{
case 'a':
case ‘A’:
case 'e':
case ‘E’:
case 'i':
case ‘I’
case 'o':
case ‘O’:
case 'u':
case ‘U’:
printf("\n The character %c is vowel!",ch);
break;
default :
printf("\n The character %c is consonant!",ch);
}
getch();
}
Input & Output:
a
The character a is vowel!
b
The character b is consonant!
Result
Thus the above program has been successfully compiled and the output has been
verified.
Ex No: 06 Program to find the area of the cylinder
Date:
Aim
Program
#include<stdio.h>
void main()
{
float area, r,h;
printf(Enter the radius and height);
scanf(“%f%f”,&r,&h);
area=3.14*r*r*h;
printf(“%f”,area);
}
Result
Thus the above program has been successfully compiled and the output has been
verified.
Ex No : 07 Program to check the given string is palindrome or not
Date :
Aim
Program
#include <stdio.h>
#include <string.h>
int main()
{
char a[100],b[100];
printf(Enter a string to checkpalindrome:”);
gets(a);
strcpy(b,a);
strrev(b);
if (strcmp(a, b) == 0) // Comparing input string with the reverse string
printf("The string is a palindrome.\n");
else
printf("The string isn't a palindrome.\n");
return 0;
}
ENTER A STRING
madam
The Given String is palindrome
ENTER A STRING
tiger
The Given String is not palindrome
Result
Thus the above program has been successfully compiled and the output has been
verified.
Ex No: 08 Program to find the largest number among three numbers
Date :
Aim
Program
#include <stdio.h>
#include<conio.h>
void main ()
{
int a,b,c;
clrscr ();
printf ("Enter the value of a,b&c:”);
scanf ("%d%d%d", &a,&b,&c);
if((a>b)&&(a>c))
printf(“\n a is largest number”);
else if((b>a)&&(b>c))
printf(“\n b is largest number”);
else
printf(“\n c is largest number”);
}
Result
Thus the above program has been successfully compiled and the output has been
verified.
Ex No :09 Prime Number Generation
Date :
Aim
Program
#include <stdio.h>
main()
{
int i,j,c;
clrscr();
printf("prime numbers between 1 to 50 \n");
for(i=2;i<=50;i++)
{
c=0;
for(j=1;j<=i;j++)
{
if((i%j)==0)
c++;
}
if(c==2)
printf("%d\n",i);
}
getch();
}
Result
Thus the above program has been successfully compiled and the output has been
verified.
Ex.No : 10 Armstrong Numbers Between 1 And 200
Date :
Aim
Program
#include<stdio.h>
void main()
{
int i,r,s,x;
clrscr();
printf(" Armstrong number between 1 to 200\n");
for(i=1;i<=200;i++)
{
s=0;
x=i;
while(x>0)
{
r=x%10;
s=s+r*r*r;
x=x/10;
}
if(i==s)
printf("%d\n",i);
}
getch();
}
Result
Thus the above program has been successfully compiled and the output has been
verified.
Ex No :11 Pascal Triangle
Date:
Aim
Program-1
#include <stdio.h>
#include <conio.h>
void main()
{
int n,i=1,j,k,m,a[10][10];
clrscr();
printf("\n\t\t\tPASCAL TRIANGLE\n");
printf("\nEnter the number of rows :");
scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=i;j++)
{
if ((j==1)||(j==i))
a[i][j]=1;
else
a[i][j]=a[i-1][j-1]+a[i-1][j];
}
printf("\n");
for(i=1;i<=n;i++)
{
for(k=35-2*i;k>0;k--)
printf(" ");
for(j=1;j<=i;j++)
printf("%4d",a[i][j]);
printf("\n\n");
}
getch();
}
Program -2
#include<stdio.h>
#include<conio.h>
void main()
{
int n,m,j,k,i=1;
clrscr();
printf("INPUT:\n");
printf("\t\t PASCAL TRIANGLE \n");
printf("\t\t *************** \n");
printf("\t\n Enter the number of lines :");
scanf("%d",&n);
for(j=0;j<n;++j)
{
for(k=35-2*j;k>0;k--)
printf(" ");
for(m=0;m<=j ;++m)
{
if((m==0)||(j==0))
i=1;
else
i=(i*(j-m+1))/m;
printf("%4d",i);
}
printf("\n");
}
getch();
}
PASCAL TRIANGLE
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Result
Thus the above program has been successfully compiled and the output has been
verified.
Ex No :12 Fibonacci Number Generation
Date :
Aim
Program
#include <stdio.h>
#include <conio.h>
void main()
{
int n,I,f1=0,f2=1;
clrscr();
printf("Fibonacci Series\n");
printf(“--------------------\n”);
printf("Enter the positive integer : ");
scanf("%d",&n);
printf("\n\nThe fibanacci series is \n");
printf(“%d \n %d \n”,f1,f2);
for(i=3;i<n;++i)
{
F3=f1+f2;
F1=f2;
f2=f3;
printf("%d\n",f3);
}
getch();
}
Fibonacci Series
-------------------
Enter the positive integer : 7
Result
Thus the above program has been successfully compiled and the output has been
verified.
Ex No : 13 Student Marksheets using structure
Date :
Aim
Program
#include<conio.h>
struct student
{
int no;
char name[10];
int m1;
int m2;
int m3;
int total;
int per;
char result[10];
char class[10];
}stu[10];
void main()
{
int n,i;
clrscr();
printf(" enter the number of students to be entered \n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&stu[i].no);
scanf("%s",stu[i].name);
scanf("%d",&stu[i].m1);
scanf("%d",&stu[i].m2);
scanf("%d",&stu[i].m3);
}
printf("----------------------------------------------------------------------------------------\n");
printf(" SNO NAME M1 M2 M3 TOT PER RESULT CLASS\n");
printf("-----------------------------------------------------------------------------------------\n\
n");
for(i=1;i<=n;i++)
{
printf(" %d\t",stu[i].no);
printf(" %s\t",stu[i].name);
printf(" %d\t",stu[i].m1);
printf(" %d\t",stu[i].m2);
printf(" %d\t",stu[i].m3);
if((stu[i].m1>50)&&(stu[i].m2>50)&&(stu[i].m3>50))
{
Stu[i].total=stu[i].m1+stu[i].m2+stu[i].m3;
Stu[i].per=stu[i].tot/3;
Strcpy(stu[i].result,”PASS”);
printf("%d\t",stu[i].tot);
printf("%d\t",stu[i].per);
printf(“%s\t”,stu[i].result);
else
strcpy(stu[i].result,”FAIL”);
printf(" *\t*\t%s”,stu[i].result);
if((stu[i].per>=50)&&(stu[i].per<60))
strcpy(stu[i].class,”SECOND”);
else if((stu[i].per>=60)&&(stu[i].per<75))
strcpy(stu[i].class,”FIRST”);
else
strcpy(stu[i].class,”DISTINCTION”);
printf(“\t%s\n”,stu[i].class);
}
printf("-------------------------------------------------------------");
getch();
}
_____________________________________________________________________
___
SNO NAME M1 M2 M3 TOT PER RESULT CLASS
Result
Thus the above program has been successfully compiled and the output has been
verified.
Ex.No : 14 Addition of two matrices using arrays
Date :
Aim
Program
#include <stdio.h>
#include <conio.h>
void main()
{
int a[2][3],b[2][3],c[2][3],i,j;
Result
Thus the above program has been successfully compiled and the output has been
verified.
Ex.No : 15 Factorial using recursion function
Date :
Aim
To write a program, to find the factorial of a given number using recursion function.
Program
#include <stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int n,f=1;
clrscr();
printf("enter the positive integer : ");
scanf("%d",&n);
f=fact(n);
printf("the factorial of %d is %d",n,f);
getch();
}
int fact(int n)
{
if (n>1)
return(n*fact(n-1));
else
return 1;
}
Result
Thus the above program has been successfully compiled and the output has been
verified.
Aim
Program
#include<stdio.h>
int main()
{
int a [20] ;
int sum, i,n;
printf(“Enter the n value\n”);
scanf(“%d”,&n);
printf(“Enter the value one by one\n”);
sum = 0;
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
sum = sum + a [i];
}
printf(“Sum of the array is %d”,sum);
return 0;
}
Result
Thus the above program has been successfully compiled and the output has been
verified.
Ex.No : 17 Write and Read Operation in File
Date :
Aim
To write a program, to write and read the data from file.
Program
#include <stdio.h>
void main()
{
FILE *fptr;
char name[20],ch;
int age;
float salary;
fptr = fopen("emp.txt", "w");
if (fptr == NULL)
{
printf("File does not exists \n");
return;
}
printf("Enter the name \n");
scanf("%s", name);
fprintf(fptr, "Name = %s\n", name);
printf("Enter the age\n");
scanf("%d", &age);
fprintf(fptr, "Age = %d\n", age);
printf("Enter the salary\n");
scanf("%f", &salary);
fprintf(fptr, "Salary = %.2f\n", salary);
fclose(fptr);
fptr = fopen("emp.txt", "r");
if (fptr == NULL)
{
printf("Cannot open file \n");
exit(0);
}
ch = fgetc(fptr);
while (ch != EOF)
{
printf ("%c", ch);
ch = fgetc(fptr);
}
fclose(fptr);
}
Result
Thus the above program has been successfully compiled and the output has been
verified.
Ex.No : 18 Swap two variables using Call by Reference
Date :
Aim
Program
#include <stdio.h>
void swap(int *, int *);
void main()
{
int a = 10;
int b = 20;
printf("Before swapping the values in main a = %d, b = %d\n",a,b);
swap(&a,&b);
printf("After swapping values in main a = %d, b = %d\n",a,b);
}
void swap (int *a, int *b)
{
int temp;
temp = *a;
*a=*b;
*b=temp;
printf("After swapping values in function a = %d, b = %d\n",*a,*b);
}
Result
Thus the above program has been successfully compiled and the output has been
verified.
Ex.No : 19 Area of circle using Macro
Date :
Aim
Program
#include <stdio.h>
#define PI 3.14159
#define AREA(r) (PI*r*r)
void main()
{
float radius,areaCircle;
printf("Enter radius\n");
scanf("%f",&radius);
areaCircle=AREA(radius);
printf("Area of Circle : %f\n",areaCircle);
}
Result
Thus the above program has been successfully compiled and the output has been
verified.