PPS File New Abhishek 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 70

PRACTICAL FILE

OF
PPS LAB PROGRAMS

Submitted to:
Miss. Pooja sangwan
CSED, DCRUST
Submitted by:
Abhishek Kumar
21001004006
M.E.D. 1st Year
INDEX
S.no. Program Date Sign.

WAP to print “hello world”


1. 23-12-21
WAP to display sum of digits of a number.
2. 23-12-21
3. WAP to display subtraction of two digits.
23-12-21
4. WAP to display multiplication of two
numbers.
24-12-21
5. WAP to display average marks.
24-12-21
WAP to convert Celsius to Fahrenheit.
6. 29-12-21
WAP to check divisibility by 5 &11
7. 29-12-21
8. WAP to check even or odd values
31-12-21
9. WAP to display the greatest among three
no.s
31-12-21
10. WAP to compare and display numbers less
or greater than 5.
5-01-22
WAP to check a year is “leap year” or not.
11. 5-01-22
12. WAP to check greatest among 3 no.s using
loop.
7-01-22
13. WAP to check whether no, is +ve or not
7-01-22
14. WAP to find roots of a quad. eqn
12-01-22
WAP to calculate simple intrest.
15. 12-01-22
WAP to create a calculater using switch case
16. 17-01-22
17. WAP to display a word using while loop
17-01-22
18. WAP to the sum of digits of a number
17-01-22
19. WAP to check whether a no. Is Armstrong or
not
19-01-22
20. WAP to find whether a no. Is palindrome or
not .
19-01-22
WAP to find a series of a no, using for loop.
21. 21-01-22
WAP to find a sum, subs ,multiply of two no
22. .s simultaneously
21-01-22
23. WAP to find whether no, is prime or not.
21-01-22
24. WAP to print a program using do while
loop.
26-01-22
WAP to swap two numbers using call by
25. reference.
26-01-22
26. WAP to print a star pattern.
28-01-22
27. WAP to print febonacci series.
28-01-22
28. WAP to print factorial of a number.
28-01-22
WAP to print a message using number.
29. 2-02-22
WAP to find sum of all numbers in an array.
30. 2-02-22
WAP to swap to numbers using call by
31. value.
5-02-22
32. WAP for user defined data type namely
student and implement it suing structure.
5-02-22
33. WAP in c using pointer of array.
5-02-22
WAP to display sum of two matrix.
34. 10-02-22
WAP to display multiply of two matrix.
35. 10-02-22
36. WAP to find transpose of a matrix.
16-02-22
37. WAP to sort an array using bubble sort.
16-02-22
38. WAP to sort an array using insertion sort.
21-02-22
39. WAP to perform binary search.
22-02-22
40. WAP to perform search in 2d array.
24-02-22
41. WAP to sort an array using quick sort.
24-02-22
WAP of strings using puts and gets
42. 27-02-22
Program no.1

Aim- Write a C program to display “Hello, World”.

Source Code-

#include<stdio.h>

void main(){

printf("Hello, World");

Output-
Program no. 2

Aim- Write a C program to display sum of two numbers.

Source Code-

#include<stdio.h>

void main()

int a,b,c;

printf("enter the values");

scanf("%d%d", &a, &b);

c=a+b;

printf("the sum of two numbers is %d", c);

Output-
Program no. 3

Aim- Write a C program to display subtraction of two numbers.

Source Code-

#include<stdio.h>

void main() {

int a,b,c;

printf("enter your values");

scanf("%d%d", &a, &b);

c=a-b;

printf("your answer is %d", c)

Output-
Program no. 4

Aim- Write a C program to display multiplication of two numbers.


Source code-

#include<stdio.h>

void main() {

int a,b,c;

printf("enter your values");

scanf("%d%d", &a, &b);

c=a*b;

printf("your answer is %d", c)

Output-
Program no. 5

Aim- Write a C program to display the average of multiple numbers.


Source Code-

#include<stdio.h>

void main() {

int a,b,c,d,e;

float X;

printf("enter your marks");

scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);

X=(a+b+c+d+e)/5;

printf("your average is %f", X)

Output-
Program no. 6

Aim- Write a C program program to display conversion of temperature


in Fahrenheit to Celsius.

Source Code-

#include<stdio.h>

void main() {

int C,F;

printf("enter temperature in fahrenheit");

scanf("%d", &F);

C=(F-32)*5/9;

printf("temperature in celsius is %d", C);

Output-
Program no. 7

Aim- Write a C program to check whether the number is divisible by 5


and 11 or not.

Source Code-

#include<stdio.h>

int main() {

int a;

printf("enter the value");

scanf("%d", &a);

if (a%11==0&a%5==0) {

printf("number is divisible by 11 and 5");

else if (a%11==0) {

printf("number is divisible by 11");

else if (a%5==0) {

printf("number is divisible by 5");

else {

printf("number is neither divisible by 5 nor 11");}


return 0;

Output-
Program no. 8

Aim- Write a C program to check whether a number is even or odd.


Source Code-

#include<stdio.h>

void main() {

int a;

printf("enter your number");

scanf("%d", &a);

if (a%2==0) {

printf("number is even");

} else { printf("number is odd");

}}

Output-
Program no. 9

Aim- Write a C program to find the greatest number among three of


them.

Source Code-

#include<stdio.h>

void main() {

int a,b,c,max;

printf("enter 3 numbers");

scanf("%d%d%d", &a, &b, &c);

max=a;

if(b>max) { max=b; }

if (c>max) { max=c; }

printf("the greatest number is %d", max);

Output-
Program no. 10

Aim- Write a C program to check whether a number is greater than 5 or


not.

Source Code-

#include<stdio.h>
void main() {

int a;

printf("enter your number");

scanf("%d", &a);

if(a>5) {

printf("the number is greater than 5");

else {

printf("the number is smaller than 5");

}}

Output-
Program no. 11

Aim- Write a C program to check whether a year is leap or not.

Source Code-

#include<stdio.h>

void main() {

int a;

printf("enter the year");

scanf("%d", &a);

if (a%4 == 0) {

printf("year is leap");

else {

printf("year is not leap");

}}

Output-
Program no. 12

Aim- Write a C program to check greatest among three by using nested


loop.

Source Code-

#include<stdio.h>

void main()

int a,b,c;

printf("enter 3 numbers");

scanf("%d%d%d", &a, &b, &c);

if(a>b) {

if(a>c) { printf("a is greatest");

Else {

printf("c is greatest");

}}

else if (b>c)

printf("b is greatest");

}
else {

printf("c is greatest");

}}

Output-
Program no. 13

Aim- Write a C program to check whether a number is positive or not.


Source Code-

#include<stdio.h>

void main() {

int a;

printf("enter your number");

scanf("%d",&a);

if(a>0) { printf("number is positive");

else {

printf("number is negative");

}}

Output-
Program no. 14

Aim- Write a C program to find the roots of a quadratic equation.


Source Code-

#include<stdio.h>

void main() {

int a,b,c,d;

float r1, r2;

printf("enter the values of a,b and c");

scanf("%d%d%d", &a, &b, &c);

d=b^2 - 4*a*c;

if (d>0) {

r1=(-b+sqrt(d))/(2*a);

r2= (-b-sqrt(d))/(2*a);

printf("root 1=%f, root 2= %f", r1, r2);

else if (d==0) {

r1=-b/(2*a);

r2=-b/(2*a);

printf("root 1=%f, root 2= %f", r1, r2);

}
else {

printf("roots are imaginary");

}}

Output-
Program no. 15

Aim- Write a C program to find simple interest.

Source Code-

#include<stdio.h>

void main()

int p,n,SI;

float r;

printf("enter your Principle, Rate of Interest, Time");

scanf("%d%f%d", &p, &r, &n);

SI = (p*n*r)/100;

printf("\n Your Simple Interest is %d", SI);

Output-
Program no. 16

Aim- Write a C program to create a calculator using switch case.

Source Code-

#include<stdio.h>

void main() {

char op;

double A, B;

printf("Enter an operator (+, -, *, /): ");

scanf("%c", &op);

printf("Enter two operands: ");

scanf("%lf %lf", &A, &B);

switch (op) { case '+': printf("%.1lf + %.1lf = %.1lf", A, B, A + B);

break;

case '-':

printf("%.1lf - %.1lf = %.1lf", A, B, A - B);

break;

case '*':

printf("%.1lf * %.1lf = %.1lf", A, B, A * B);

break;

case '/':
printf("%.1lf / %.1lf = %.1lf", A, B, A / B);

break;

default:

printf("Error! operator is not correct");

}}

Output-
Program no. 17

Aim- Write a C program to display “hello- world” multiple times using


While loop.

Source Code-

#include<stdio.h>

void main()

{ int i = 0;

while (i < 50)

printf("hello- world" , i );

i = i + 1;

}}
Program no. 18

Aim- Write a C program to find the sum of digits of a number.


Source Code-
#include<stdio.h>
void main() {
int n, sum = 0, r;
printf("enter any number");
scanf("%d", &n);
while (n>0) {
r = n % 10;
sum = sum + r;
n = n/10;
}
printf("sum of digits %d", sum);
}

Output-
Program no. 19
Aim- Write a C program to find whether the number is Armstrong or no
#include<stdio.h>
int main() {
int n,r,sum=0,temp;
printf("enter your number");
scanf("%d",&n);
temp=n;
while(n>0) {
r=n%10;
sum=sum+(r*r*r);
n=n/10;}
if(temp==sum)
printf("armstrong number ");
else
printf("not armstrong number");
return 0;
}
Program no. 20
Aim- WAP to find whether the number is Palindrome or not
Source Code-
#include<stdio.h>
int main() {
int n,r,sum=0,temp;
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0) {
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
printf("palindrome number ");
else
printf("not palindrome");
return 0;
}
Output-
Program no. 21

Aim- Write a C Program to print a series of number using for loop.


Source Code-

#include<stdio.h>

void main() {

int i = 0;

for(i = 1; i< 10; i++ ){

printf("%d \n", i);

}}

Output-
Program no. 22

Aim- Write a C program to find sum, subtraction, multiply and division


of two numbers simultaneously.

Source Code-

#include<stdio.h>

int main() {

int a,b,add, sub, mul;

float div;

printf("enter two numbers");

scanf("%d%d", &a, &b);

add = a + b;

sub = a - b;

mul = a * b;

div = a / b;

printf(" the answer is \n %d \n %d \n %d \n %f ", add, sub, mul, div );


return 0; }

Output-
Program no. 23

Aim- Write a C program to find whether the number is prime or not.


#include<stdio.h>
int main() {
int n,i,m=0,flag=0;
printf("Enter the number to check prime:");
scanf("%d",&n);
m=n/2;
for(i=1;i<=m;i++) {
if(n%i==0) {
printf("Number is not prime");
flag=1;
break;
}}
if(flag==0)
printf("Number is prime");
return 0;
}
Output-
Program no. 24

Aim – Write a C program to print a series of number using do while


loop.

Source Code-

#include<stdio.h>

void main() {

int a=10;

do {

printf("value of a is %d \n", a);

a = a + 1; }

while (a<20)

Output-
Program no. 25

Aim- Write a C program to swap two numbers using call by reference.


Source Code-

#include<stdio.h>

int main() {

int a,b,temp;

printf("enter two numbers:");

scanf("%d%d", a, b);

temp = a;

a = b;

b = temp;

printf("%d%d", a, b);

return 0;

Output-
Program no. 26

Aim- Write a C program to print a pattern.

Source Code-
#include<stdio.h>
int main() {
int n;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=1;i<=n;i++) {
for(int j=1;j<=i;j++) {
printf("* ");
}
printf("\n");
}
return 0;
}
Output-
Program no. 27

Aim- Write a C program to print a series of Fibonnaci numbers using


recursion.

Source Code-

#include<stdio.h>
#include<conio.h>
int fibonacci(int);
int main(){
int n, i;
printf("Enter the number of element you want in series :\n");
scanf("%d",&n);
printf("fibonacci series is : \n");
for(i=0;i<n;i++) {
printf("%d ",fibonacci(i));
}
getch();
}

int fibonacci(int i){


if(i==0) return 0;
else if(i==1) return 1;
else
return (fibonacci(i-1)+fibonacci(i-2));
}
Output-
Program no. 28

Aim- Write a C program to print factorial of a number.

Source Code-

#include<stdio.h>

long int multiplyNumbers(int n);

int main() {

int n;

printf("Enter a positive integer: ");

scanf("%d",&n);

printf("Factorial of %d = %ld", n, multiplyNumbers(n));

return 0;

long int multiplyNumbers(int n) {

if (n>=1)

return n*multiplyNumbers(n-1);

else

return 1;

}
Output-
Program no. 29

Aim- Write a C program to print a message using functions.

Source Code-
#include<stdio.h>
void main()
printMessage() {
printf("This is user defined function");
}
void main()
{
printf("This is main Function! \n");
PrintMessage();
}
Output-
Program no. 30
Aim- Write a C program to find sum of all numbers in an array.
Source Code-
#include<stdio.h>
#include<conio.h>
int main()
{
int i, a[5], sum=0;
for(i=0; i<5; i++)
scanf("%d",&a[i]);
for(i=0; i<5; i++)
{
sum=sum+a[i];
}
printf("%d",sum);
getch();
}
Output-
Program no. 31

Aim- Write a C program to swap two numbers using call by value.


Source Code-

#include<stdio.h>

void swap(int, int);

int main(){
int x, y;

printf("Enter the value of x and y\n");


scanf("%d%d",&x,&y);

printf("Before Swapping\nx = %d\ny = %d\n", x, y);

swap(x, y);

printf("After Swapping\nx = %d\ny = %d\n", x, y);

return 0;
}
void swap(int a, int b)
{
int temp;

temp = a;
a = b;
b = temp;
printf("Values of a and b is %d %d\n",a,b);

}
Output-
Program no. 32

Aim- Write a C program for user defined data type namely student and
implement it using structure.
Source Code-
#include <stdio.h>
struct student {
char name[50];
int roll;
float marks;
} s;

int main() {
printf("Enter information:\n");
printf("Enter name: ");
fgets(s.name, sizeof(s.name), stdin);

printf("Enter roll number: ");


scanf("%d", &s.roll);
printf("Enter marks: ");
scanf("%f", &s.marks);

printf("Displaying Information:\n");
printf("Name: ");
printf("%s", s.name);
printf("Roll number: %d\n", s.roll);
printf("Marks: %.1f\n", s.marks);

return 0;
}
Output-
Program no. 33

Aim- Write a C program by using pointer for array.

Source Code-

#include <stdio.h>

int main() {

int x[5] = {1, 2, 3, 4, 5};

int* ptr;

ptr = &x[2];

printf("*ptr = %d \n", *ptr); // 3

printf("*(ptr+1) = %d \n", *(ptr+1)); // 4

printf("*(ptr-1) = %d", *(ptr-1)); // 2

return 0;

Output-
Program no. 34

Aim- WAP to display sum of two matrix.

Source Code-

#include<stdio.h>
#include<conio.h>
int main()
{
int r, c, a[100][100], b[100][100], sum[100][100], i, j;
printf("Enter the number of rows (between 1 and 100): ");
scanf("%d", &r);
printf("Enter the number of columns (between 1 and 100): ");
scanf("%d", &c);

printf("\nEnter elements of 1st matrix:\n");


for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j)
{
printf("Enter element a%d%d: ", i + 1, j + 1);
scanf("%d", &a[i][j]);
}

printf("Enter elements of 2nd matrix:\n");


for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j)
{
printf("Enter element b%d%d: ", i + 1, j + 1);
scanf("%d", &b[i][j]);
}
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j)
{
sum[i][j] = a[i][j] + b[i][j];
}
printf("\nSum of two matrices: \n");
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j)
{
printf("%d ", sum[i][j]);
if (j == c - 1)
{
printf("\n\n");
}
}
return 0;
}
Output-
Program no. 35

Aim- Write a C program to print multiply of two matrix.

Source Code-

#include<stdio.h>
#include<conio.h>
int main()
{
int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;
printf("enter the number of row=");
scanf("%d",&r);
printf("enter the number of column=");
scanf("%d",&c);
printf("enter the first matrix element=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter the second matrix element=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&b[i][j]);
}
}

printf("multiply 1 and 2 matrix=\n");


for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
mul[i][j]=0;
for(k=0;k<c;k++)
{
mul[i][j]+=a[i][k]*b[k][j];
}
}
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",mul[i][j]);
}
printf("\n");
}
return 0;
}
Output-
Program no. 36

Aim- Write a C program to print transpose of a matrix.

Source Code-

#include <stdio.h>
#include<conio.h>
int main()
{
int a[10][10], transpose[10][10], r, c;
printf("Enter rows and columns ");
scanf("%d %d", &r, &c);
printf("\nEnter matrix elements");
for (int i = 0; i < r; ++i)
for (int j = 0; j < c; ++j)
{
printf("Enter element a%d%d: ", i + 1, j + 1);
scanf("%d", &a[i][j]);
}
printf("\nEntered matrix");
for (int i = 0; i < r; ++i)
for (int j = 0; j < c; ++j)
{
printf("%d ", a[i][j]);
if (j == c - 1)
printf("\n");
}
for (int i = 0; i < r; ++i)
for (int j = 0; j < c; ++j)
{
transpose[j][i] = a[i][j];
}
printf("\nTranspose of the matrix");
for (int i = 0; i < c; ++i)
for (int j = 0; j < r; ++j)
{
printf("%d ", transpose[i][j]);
if (j == r - 1)
printf("\n");
}
return 0;
}
Output-
Program no. 37

Aim- Write a C program to sort the array using bubble sort.

Source Code-

#include <stdio.h>

int main()

int array[100], n, c, d, swap;

printf("Enter number of elements\n");

scanf("%d", &n);

printf("Enter %d integers\n", n);

for (c = 0; c < n; c++)

scanf("%d", &array[c]);

for (c = 0 ; c < n - 1; c++)

for (d = 0 ; d < n - c - 1; d++)


{

if (array[d] > array[d+1])

swap = array[d];

array[d] = array[d+1];

array[d+1] = swap;

printf("Sorted list in ascending order:\n");

for (c = 0; c < n; c++)

printf("%d\n", array[c]);

return 0;

}
Output-
Program no. 38

Aim- Write a C program to sort the array using insertion sort.

Source Code-

#include <stdio.h>

int main()

int n, i, j, temp;

int arr[64];

printf("Enter number of elements\n");

scanf("%d", &n);

printf("Enter %d integers\n", n);

for (i = 0; i < n; i++)

scanf("%d", &arr[i]);

for (i = 1 ; i <= n - 1; i++)

j = i;
while ( j > 0 && arr[j-1] > arr[j])

temp = arr[j];

arr[j] = arr[j-1];

arr[j-1] = temp;

j--;

} }

printf("Sorted list in ascending order:\n");

for (i = 0; i <= n - 1; i++) {

printf("%d\n", arr[i]);

return 0;

Output-
Program no. 39

Aim- Write a C program to perform binary search.

Source Code-

#include <stdio.h>

int binarySearch(int array[], int x, int low, int high) {

if (high >= low) {

int mid = low + (high - low) / 2;

if (array[mid] == x)

return mid;

if (array[mid] > x)

return binarySearch(array, x, low, mid - 1);

return binarySearch(array, x, mid + 1, high);

return -1;}

int main(void) {

int array[] = {3, 4, 5, 6, 7, 8, 9};

int n = sizeof(array) / sizeof(array[0]);

int x = 4;

int result = binarySearch(array, x, 0, n - 1);


if (result == -1)

printf("Not found");

else

printf("Element is found at index %d", result);

Output-
Program no. 40

Aim- Write a C program to perform searching in 2d array.

Source Code-

#include<stdio.h>

int main(){
int m, n, item, count=0, array[10][10];

printf("Enter the number of rows and columns: ");


scanf("%d %d", &m, &n);

printf("Enter %d elements: ", (m*n));


for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
scanf("%d", &array[i][j]);
}
}

printf("Enter the item to find: ");


scanf("%d", &item);
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
if(array[i][j] == item){
printf("Item found at [%d, %d] \n", i, j);
count++;
}
}
}
if(count==0)
printf("Item Not found");
return 0;
}
Output-
Program no. 41

Aim- Write a C program to sort an array using quick sort.

Source Code-

#include <stdio.h>

void swap(int *a, int *b) {

int t = *a;

*a = *b;

*b = t;

int partition(int array[], int low, int high) {

int pivot = array[high];

int i = (low - 1);

for (int j = low; j < high; j++) {

if (array[j] <= pivot) {

i++;

swap(&array[i], &array[j]);

swap(&array[i + 1], &array[high]);

return (i + 1);}
void quickSort(int array[], int low, int high) {

if (low < high) {

int pi = partition(array, low, high);

quickSort(array, low, pi - 1);

quickSort(array, pi + 1, high);

void printArray(int array[], int size) {

for (int i = 0; i < size; ++i) {

printf("%d ", array[i]);

printf("\n");

int main() {

int data[] = {8, 7, 2, 1, 0, 9, 6};

int n = sizeof(data) / sizeof(data[0]);

printf("Unsorted Array\n");
printArray(data, n);

quickSort(data, 0, n - 1);

printf("Sorted array in ascending order: \n");

printArray(data, n);

Output-
Program no. 42

Aim- Write a C program of string using puts and gets.

Source Code-

#include<stdio.h>

void main ()

char s[30];

printf("Enter the string? ");

gets(s);

printf("You entered %s",s);

Output-

You might also like