[go: up one dir, main page]

0% found this document useful (0 votes)
6 views18 pages

PSP Lab Manual.docx

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 18

Ex No: 01 Algorithm, Pseudocode, and Flowchart for

Calculating Simple Interest


Date:

Aim

To Write an algorithm, Pseudocode and draw a 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

1
Pseudocode

BEGIN

READ P, n, r

CALCULATE SI

SI=P*n*r/10
0 DISPLAY
SI END

Result

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

2
Ex No: 02 Program to Perform Arithmetic Operations

Date:

Aim

To perform various arithmetic operations.

Program

#include<stdio.h>
#include<conio.h
> void main()
{
int a, 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.

3
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.

4
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.
5
Ex No: 05 Program to Check Vowels or Consonants Using
Switch Case
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.

6
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.
7
Ex No: 07 Program to check the given String is Palindrome or Not

Date:

Aim

To check whether 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 check palindrome:”);
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.

8
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.

9
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.
10
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.

11
Ex No:11 Pascal Triangle
Date:

Aim

To write a program, to print the Pascal triangle.

Program

#include<stdio.h>
#include<conio.>
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();
}

12
Input & Output

PASCAL TRIANGLE

Enter the number of rows :5

11

12 1

13 3 1

14 6 4 1

Result

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

13
Ex No :12 Fibonacci Number Generation
Date :

Aim

To write a program, to generate the 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.
14
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;
15
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

16
Ex.No: 14 Factorial using recursion function
Date:

Aim

To write a program, to find the factorial of a given number using the 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.

17
Ex.No: 15 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.

18

You might also like