Pps Lab
Pps Lab
Program :
#include<stdio.h>
#include<conio.h>
void swap(int,int);
int main()
int a,b;
scanf("%d%d",&a,&b);
swap(a,b);
getch();
int temp;
temp=a;
a=b;
b=temp;
--------------------------------------------------------------------------------------------------
Output:
---------------------------------------------------------------------------------------------------
Program:
#include<stdio.h>
#include<stdlib.h>
int main()
scanf("%d", &size);
scanf("%d", &array[c]);
maximum = array[0];
maximum = array[c];
location = c+1;
}
maximum);
return 0;
}
-----------------------------------------------------------------------------------------------------------------------
Output:
--------------------------------------------------------------------------------------------------------------------------
Enter 5 integers
Program:
#include <stdio.h>
int main()
scanf("%s", s1);
printf("Enter second string: ");
scanf("%s", s2);
s1[i] = s2[j];
s1[i] = '\0';
return 0;
-------------------------------------------------------------------------------------------------------------
Output
--------------------------------------------------------------------------------------------------------------
Program
printf("Displaying Information:\n\n");
// displaying information
{
printf("\nRoll number: %d\n",i+1);
printf("Name: ");
puts(s[i].name);
printf("Marks: %.1f",s[i].marks);
printf("\n");
return 0;
Output
--------------------------------------------------------------------------------------------------------------------------
Enter information of students:
Enter marks: 98
Enter marks: 89
..
Displaying Information:
Roll number: 1
Name: Tom
Marks: 98
Enter marks: 89
5. Write a program to compute matrix multiplication.
Program
#include <stdio.h>
int main()
{
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];
printf("\nEnter the number of rows and columns of first matrix:\n");
scanf("%d%d", &m, &n);
/*//Entering elements of first matrix
printf("\n Enter the elements of first matrix\n");
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
scanf("%d", &first[c][d]);*/
printf("\nEnter the number of rows and columns of second matrix:\n");
scanf("%d%d", &p, &q);
//Checking if Matrix Multiplication is possible
if ( n != p )
{
printf("\nMatrices with entered orders can't be multiplied with each other.\n");
printf("\nThe column of first matrix should be equal to row of second.\n");
}
else
{
//Entering elements of first matrix
printf("\nEnter the elements of first matrix:\n");
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
scanf("%d", &first[c][d]);
//Entering elements of second matrix
printf("\nEnter the elements of second matrix:\n");
for ( c = 0 ; c < p ; c++ )
for ( d = 0 ; d < q ; d++ )
scanf("%d", &second[c][d]);
//Carrying out matrix multiplication operation
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < q ; d++ )
{
for ( k = 0 ; k < p ; k++ )
{
56
sum = sum + first[c][k]*second[k][d];
}
multiply[c][d] = sum;
sum = 0;
}
}
//Printing the final product matrix
printf("\nThe product of entered matrices is:\n");
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < q ; d++ )
printf("%d\t", multiply[c][d]);
printf("\n");
}
}
return 0;
}
Output
_-------------------------------------------------------------------------------------------------------------------
Enter the number of rows and columns of first matrix:
22
Program.
int main()
{
char str[1000], ch;
int i, frequency = 0;
printf("Enter a string: ");
gets(str);
printf("Enter a character to find the frequency: ");
scanf("%c", &ch);
for(i = 0; str[i] != '\0'; ++i)
{
if(ch == str[i])
++frequency;
}
printf("Frequency of %c = %d", ch, frequency);
return 0;
}
Output
---------------------------------------------------------------------------------------------------------------------
Enter a string: This website is awesome.
Enter a character to find the frequency: e
Frequency of e = 4
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main( )
{
int i;
FILE *fp;
char arr[115] = "welcome to c programming sec sasaram";
{
printf ("errror while opening file");
}
else {
{
fputc(arr[i], fp);
printf("%c ", arr[i]);
fclose (fp);
getch();
return 0;
}
Output
Program.
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main( )
{
char ch ;
FILE *fp;
char arr[115] = "welcome to c programming sec sasaram";
{
printf ("errror while opening file");
}
else {
}
while( ch != EOF)
{
ch = fgetc(fp);
printf(" %c ", ch);
fclose (fp);
getch();
return 0;
}
Output
Program.
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main ()
{
FILE *fp ;
char input [200];
fp = fopen("sasaram.txt", "w");
if ( fp == NULL)
{
}
else{
fputs(input , fp);
printf(" string written to file successfully");
fclose(fp);
getch();
return 0;
}
Output
10 Write a program to read string from file using fgets fuction.
Program
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main ()
FILE *fp ;
char ch [200];
fp = fopen("sasaram.txt", "r");
if ( fp == NULL)
else{
printf ("file opened successfully\n");
while(!feof(fp))
printf("%s",ch);
fclose(fp);
getch();
return 0;
Output