0% found this document useful (0 votes)
11 views23 pages

PSP Lab Record

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views23 pages

PSP Lab Record

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 23

Ex No: 01 Algorithm, Pseudocode and Flowchart for Calculating simple interest

Date:

Aim

To Write an algorithm, Pseudocode and draw Flowchart for Calculating simple

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

To perform various arithmetic operations

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:

Enter a and b value


 10 2
Addition=12
Subtraction=8
Multiplication=20
Division=5
Reminder=0

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

To find the area of the circle

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

To check whether a given number is Positive or Negative or Zero.

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();
}

Input & Output

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:

Enter any character

a
The character a is vowel!

Enter any character

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

To find the area of the circle

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);
}

Input & Output:


Enter the value 1 1
314.0000

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

To check the given string is palindrome or not.

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;
       }

Input & Output

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

To find the smallest and largest number among ‘n’ numbers

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”);
  }

Input & Output

Enter the value of a,b&c:10 20 30


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

To write a program, to generate prime numbers between 1 and 50.

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();
}

Input & Output

Prime numbers between 1 to 50


1
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47

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

To generate Armstrong numbers between 1 and 200.

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();
}

Input & Output

Armstrong number between 1 to 200


1
153

Result

Thus the above program has been successfully compiled and the output has been
verified.
Ex No :11 Pascal Triangle
Date:

Aim

To write a program, to print the Pascal triangle.

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();
}

Input & Output

PASCAL TRIANGLE

Enter the number of rows :5

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

To write a program, to generate fibonacci series using FOR LOOP.

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();
}

Input & Output

Fibonacci Series
-------------------
Enter the positive integer : 7

The fibanacci series is


0
1
1
2
3
5
8

Result

Thus the above program has been successfully compiled and the output has been
verified.
Ex No : 13 Student Marksheets using structure
Date :

Aim

Generate student mark sheets using structure

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();
}

Input & Output

Enter the number of students to be entered


3
1
AAA
50
50
50
2
SSS
60
60
49
3
BBB
90
90
90

_____________________________________________________________________
___
SNO NAME M1 M2 M3 TOT PER RESULT CLASS

1 AAA 50 50 50 150 50 PASS SECOND


2 SSS 60 60 49 * * FAIL *
3 BBB 90 90 90 270 90 PASS
DISTINCTION
_____________________________________________________________________
___

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

To write a program, to find the addition of two matrices using arrays.

Program

#include <stdio.h>
#include <conio.h>
void main()
{
int a[2][3],b[2][3],c[2][3],i,j;

printf("\nENTER VALUES FOR MATRIX A:\n");


for(i=0;i<2;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
printf("\nENTER VALUES FOR MATRIX B:\n");
for(i=0;i<2;i++)
for(j=0;j<3;j++)
scanf("%d",&b[i][j]);
for(i=0;i<2;i++)
for(j=0;j<3;j++)
c[i][j]=a[i][j]+b[i][j];
printf("\nTHE VALUES OF MATRIX C ARE:\n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
printf("%5d",c[i][j]);
printf("\n");
}
getch();
}

Input & Output

ENTER VALUES FOR MATRIX A : 1 2 3


456
ENTER VALUES FOR MATRIX B : 2 4 6
538
THE VALUES OF MATRIX C ARE : 3 6 9
9 8 14

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;
}

Input & Output

Enter the positive integer : 4


The factorial of 4 is 24

Result

Thus the above program has been successfully compiled and the output has been
verified.

Ex.No : 16 Sum of the elements in the array


Date :

Aim

To write a program, to find the sum of n elements in the array

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;
}

Input & Output

Enter the n value : 10


Enter the value one by one
0
1
2
3
4
5
6
7
8
9
Sum of the array is 45

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);
}

Input & Output


Enter the name : Rajesh
Enter the age : 21
Enter the salary : 22000.00
Name = Rajesh
Age = 21
Salary = 22000.00

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

To write a program, to swap two variables using Call by Reference(pointers).

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);
}

Input & Output


Before swapping the values in main a =10,b=20
After swapping values in function a =20,b=10
After swapping values in main a =20,b=10

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

To write a program, to calculate Area of Circle using Macro.

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);
}

Input & Output


Enter radius : 3.3
Area of Circle : 34.211914

Result

Thus the above program has been successfully compiled and the output has been
verified.

You might also like