Practical of 'PPS' file
Practical of 'PPS' file
Practical of 'PPS' file
OF TECHNOLOGY
&MANAGEMENT MURTHAL,
SONIPAT, HARYANA
Practical file
Of
Programming and
problem solving using C
#include<stdio.h>
int main()
{
int num1, num2, num3;
printf("\n Ener value of num1, num2 and num3:");
scanf("%d %d %d", &num1, &num2, &num3);
if ((num1>num2)&&(num1>num3))
printf("\n Number1 is greatest amng three");
else if((num2>num3)&&(num2>num1))
printf("\n Number2 is greatest among three");
else
printf("\n Number3 is greatest among three");
return 0;
}
Output
PROGRAM NO: 2
/* Program to find the largest number out of n numbers using for statement*/
#include <stdio.h>
#include <conio.h>
int main()
{
int i,num,n,large=0;
printf("How many numbers: ");
scanf("%d",&n);
getch();
return 0;
}
OUTPUT
PROGRAM NO: 3
/* Program to multiply two matrices*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;
system("cls");
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("Input a string\n");
gets(s);
r[begin] = '\0';
printf("%s\n", r);
return 0;
}
Output
PROGRAM NO : 5
/*Program to concatenate two strings*/
#include <stdio.h>
#include <string.h>
int main()
{
char Str1[100], Str2[100];
int i, j;
Str1[i] = Str2[j];
}
Str1[i] = '\0';
return 0;
}
Output
PRACTICAL NO : 6
/*Swapping two integers using pointers*/
#include <stdio.h>
void swap(int *x,int *y)
{
int t;
t = *x;
*x = *y;
*y = t;
}
int main()
{
int num1,num2;
printf("Enter value of num1: ");
scanf("%d",&num1);
printf("Enter value of num2: ");
scanf("%d",&num2);
printf("Before Swapping: num1 is: %d, num2 is:
%d\n",num1,num2);
swap(&num1,&num2);
printf("After Swapping: num1 is: %d, num2 is:
%d\n",num1,num2);
return 0;
}
Output
PRACTICAL NO : 7
Bubble Sort
//Bubble Sort
#include<conio.h>
#include<stdio.h>
int main()
{
int i,j,a[20],n,tmp;
printf("Enter how much element you want in this array:\
n"); scanf("%d",&n);
printf("Enter %d in the array :\n",n);
for (i=0;i<n;i++) scanf("\n
%d",&a[i]);
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{
tmp=a[j];
a[j]=a[j+1];
a[j+1]=tmp;
}
}
}
printf("Sorted array is :\n");
for(i=0;i<n;i++)
{
printf("\n%d",a[i]);
} getch();
}
OUTPUT
PRACTICAL NO : 8
Selection Sort
#include
<stdio.h>
int main()
{
int data[100],i,n,steps,temp;
printf("Enter the number of elements to be sorted:
"); scanf("%d",&n);
for(i=0;i<n;++i)
{
printf("%d. Enter element: ",i+1);
scanf("%d",&data[i]);
}
for(steps=0;steps<n;++steps)
for(i=steps+1;i<n;++i)
{ if(data[steps]>d
ata[i])
//To sort in descending order, change > to <.
{
temp=data[steps];
data[steps]=data[i];
data[i]=temp;
}
}
printf("In ascending
order: "); for(i=0;i<n;+
+i) printf("%d
",data[i]); return 0;
}
OUTPUT