BX4002 - PSP Program
BX4002 - PSP Program
Circle
Date :
Aim:
Algorithm:
Program :
#include <stdio.h>
#include
<conio.h> void
main()
{
double radius,area;
clrscr();
Printf(“Enter the Value of Radius:”); Scanf(“%2d\
n”, &radius);
area= 3.14 * radius * radius;
printf("Area of the Circle Value is:%lf", area);
getch();
Output:
Enter the Value of Radius: 10
Area of the Circle Value is : 314
Result:
Ex. No: 1 (b) Program to implement a Area of a Triangle
Date :
Aim:
Algorithm:
Program :
#include <stdio.h>
#include
<conio.h> void
main()
{
double breath,height,area;
clrscr();
Printf(“Enter the Values of Breath and Height:”);
scanf("%lf%lf", &breath,&height);
area= 0.5 * breath * height;
printf("Area of the Triangle Value is:%lf", area);
getch();
Output:
Enter the Value of Breath and Height: 10 20
Area of the Triangle Value is : 100
Result:
Ex. No: 2 (a) Program to check whether the given number is Even or
Odd
Date :
Aim:
Algorithm:
Program :
#include <stdio.h>
#include
<conio.h> void
main()
{
int number;
Printf(“Enter the Number:”);
scanf("%d", &number);
if ( number % 2 ==1)
printf("The Given number is Odd");
else
printf("The Given number is Even");
}
Output:
Enter the Number: 20
The Given number is Even
Enter the Number:15
The Given number is Odd
Result:
Ex. No: 2 (b) Program to perform a Biggest of 2
Numbers
Date :
Aim:
Algorithm:
Program :
#include <stdio.h>
#include
<conio.h> void
main()
{
int a,b;
clrscr();
scanf("%d%d",&a,&b);
if ( a>b)
else }
getch();
printf(“A is Big”);
printf(“B is Big”);
Output:
Enter the Value of A & B: 10 20
B is Big
Enter the Value of A & B: 200 150
A is Big
Result:
Ex. No: 3 (a) Program to implement Pascal’s
Triangle
Date :
Aim:
Algorithm:
Program :
#include<stdio.h>
#include<conio.h>
void main()
{
int noline,i,j,temp;
clrscr(); printf("\n\
n");
printf("\t\t\t Pascal Triangle\n");
printf("\t\t\t ***************\n\n");
printf("\tEnter The Number Of Line To Print :\t");
scanf("%d",&noline);
for(i=1;i<=noline;i++)
{
for(j=1;j<=noline-i;j++)
printf(" ");
temp=i; for(j=1;j<=i;j+
+) printf("%4d",temp+
+); temp=temp-2;
for(j=1;j<i;j++)
printf("%4d",temp--);
printf("\n\n");
}
printf("\n");
getch();
}
Output:
*
**
***
****
*****
******
Result:
Ex. No: 3 (b) Program to perform a Factorial of a Number
Date :
Aim:
Algorithm:
Program :
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int i,n,f;
char c;
clrscr();
printf("\n\n\n\t\t\tFactorial Number\n");
do
{
printf("\n\nEnter the number\n");
scanf("%d",&n);
printf("Factorial is %d \n",fact(n)); printf("\
n\nDo you want to continue [Y/N]");
c=getch();
}
while(c=='Y' || c=='y');
}
int fact(int n)
{
int f;
if(n==1)
return(1);
else
f=n*fact(n-1);
return(f);
}
Output:
Enter the Value of Breath and Height: 10 20
Area of the Triangle Value is : 100
Result:
Ex. No: 3 (c) Program to perform a Fibonacci
Series
Date :
Aim:
Algorithm:
Program :
#include<stdio.h>
#include<conio.h>
void main()
{
int num,fib=0,a=0,b=1; int
i;
clrscr(); printf("\n\
n");
printf("\t\t\tFibonacci Series\n"); printf("\t\t\
t****************\n\n"); printf("\t\tEnter
The Number is :\t"); scanf("%d",&num);
printf("\n\t\tFibonacci Series is :\n");
if(num==0)
printf("0"); else
{
for(i=0;i<num;i++)
{
fib=fib+a;
a=b; b=fib;
printf("\t\t\t\t\t%d\n",fib);
}
}
getch();
}
Output:
Enter the Value of Breath and Height: 10 20
Area of the Triangle Value is : 100
Result:
Ex. No: 4 Program to find the Largest element of an array using the Function
Date :
Aim:
Algorithm:
Program:
#include <stdio.h>
int findLarge(int[],int);
int main()
int a[100],a_size,L_Num,i;
scanf(“%d”,&a_size);
+)
scanf(“%d”,&a[i]);
L_Num=findLarge(a,a_size);
return 0;
int i,Large_num;
Large_num=a[0];
for(i=1;i<a_size;i++)
if(Large_num<a[i])
Large_num=a[i];
return Large_num;
Output:
Enter size of array: 5
Result:
Ex. No: 5 Program to Display all Prime numbers between 2 intervals using
Function
Date :
Aim:
Algorithm:
Program :
#include <iostream>
using namespace std;
cout << "Enter two positive integers: "; cin >> n1 >> n2;
if(flag)
cout << i << ", ";
}
return 0;
}
return is_prime;
}
Output:
Enter two positive integers: 12 30
Prime numbers between 12 and 30 are: 13 17 19 23 29
Result:
Ex. No: 6 Program to Reverse a String using Recursion
Date :
Aim:
Algorithm:
Program :
#include<stdio.h>
#define MAX 100
char* ReverseOfString(char[]);
int main()
{
char str1[MAX],*revstr;
printf("\n\n Recursion : Get reverse of a string :\n");
printf(" \n");
Result:
Ex. No: 7 Program to Concatenate 2
Strings
Date :
Aim:
Algorithm:
Program :
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str1[50], str2[50];
printf("Enter first string: ");
gets(str1);
printf("Enter second string: ");
gets(str2);
strcat(str1, str2);
printf("\n String after concatenation is:\n %s", str1);
getch();
return 0;
}
Output:
Enter first string: Mani
Enter second string: Maran
String after concatenation is: Mani Maran
Result:
Ex. No: 8 Program to Store Student Information using Structure and display
it
Date :
Aim:
Algorithm:
Program :
#include <stdio.h>
struct student
{
char name[50];
int roll;
float marks;
}
stud[2];
int main()
{
int i;
printf("Enter information of students:\n");
// storing information
for(i=0; i<2; ++i)
{
stud[i].roll = i+1;
printf("\nEnter roll number: %d\n",stud[i].roll);
printf("Enter name: ");
scanf("%s",stud[i].name);
printf("Enter marks: ");
scanf("%f",&stud[i].marks);
printf("\n");
}
printf("Displaying Information:\n\n");
// displaying information
for(i=0; i<2; ++i)
{
printf("\nRoll number: %d\n",i+1);
printf("Name: ");
puts(stud[i].name);
printf("Marks: %.1f",stud[i].marks);
printf("\n");
}
return 0;
}
Output:
Enter the Information of Students:
Displaying Information:
Roll number: 1
Name: John
Marks: 85
Roll number: 2
Name:
Krishna
Marks: 92
Result:
Ex. No: 9 Program to implement the Sequential Access
File
Date :
Aim:
Algorithm:
Program:
Program output:
Account Name Balance
100 Samuel 24.98
200 Martin 345.67
300 White 0.00
400 Stone -42.16
500 Rich 224.62
Result:
Ex. No: 10 Program to implement the Random Access
File
Date :
Aim:
Algorithm:
Program :
#include <stdio.h>
// clientData structure definition
struct clientData {
unsigned int acctNum; // account number char
lastName[ 15 ]; // account last name char
firstName[ 10 ]; // account first name double
balance; // account balance
}; // end structure clientData int
main( void ) {
unsigned int i; // counter used to count from 1-100
#include <stdio.h>
// clientData structure definition struct clientData {
unsigned int acctNum; // account number char lastName[ 15 ]; // account last name char
firstName[ 10 ]; // account first name double balance; // account balance
}; // end structure clientData
} // end if else {
// require user to specify account number printf( "%s", "Enter account number"
" ( 1 to 100, 0 to end input )\n? " ); scanf( "%d", &client.acctNum );
// set record lastName, firstName and balance value fscanf( stdin, "%14s%9s%lf",
client.lastName,client.firstName, &client.balance );
// enable user to input another account number printf( "%s", "Enter account number\n? " );
scanf( "%d", &client.acctNum );
} // end while
fclose( cfPtr ); // fclose closes the file
} // end else
} // end main
OUTPUT:
Result: