SPL Lab 8
SPL Lab 8
Submitted to-
Md. Rafsan Jani
Assistant Professor
Department of Computer Science and Engineering
Jahangirnagar University
Savar, Dhaka-1342
Sobhana Jahan
Lecturer
Department of Computer Science and Engineering
Bangladesh University of Professionals
Mirpur Cantonment, Dhaka-1216
Problem Description:
Write a C program to input two integers R, C, representing the rows and columns of a 2D array. Next, input R
lines. Each line will have C integers. Finally, compute and print the sum of each column.
Source Code:
#include<stdio.h>
int main(void)
int R,C;
printf("Enter the row and column number \n");
scanf("%d %d",&R,&C)
int arr[R][C];
int sum[C];
scanf("%d",&arr[i][j]);
sum[j]=0;
sum[j]+=arr[i][j];
for(int j=0;j<C;j++){
printf("%d\n",sum[j]);
Output:
Problem Description:
Write a C program to input two integers R, C, representing the rows and columns of a 2D array. Next, input R
lines. Each line will have C integers. Finally, print the maximum number of each row.
Source Code:
#include<stdio.h>
int main(void)
{
int R,C;
printf("Enter the row and column number \n");
scanf("%d %d",&R,&C);
int arr[R][C];
for(int i=0; i<R; i++)
{
for(int j=0; j<C; j++)
{
scanf("%d",&arr[i][j]);
}
}
for(int i=0; i<R; i++)
{
int max =arr[i][0];
for(int j=0; j<C; j++)
{
if(arr[i][j]>max)
{
max= arr[i][j];
}
}
printf("%d\n",max);
}
}
Problem Description:
Write a C program that takes an integer as input, Then 𝑁 print the frequency of its digits.
Source Code:
#include<stdio.h>
int main(void)
{
int N;
int frq[10]={0};
scanf("%d",&N);
N=N/10;
}
for(int i=0;i<10;i++){
printf("%d",frq[i]);
}
Output:
Source Code:
#include<stdio.h>
int main(void)
{
int m,n;
scanf("%d %d",&m,&n);
int a[m],b[n],c[n];
for(int i=0; i<m; i++)
{
scanf("%d",&a[i]);
}
for(int i=0; i<n; i++)
{
scanf("%d",&b[i]);
}
int i=0,j=0,k=0;
while(i<m && j<n)
{
if(a[i]<b[j])
{
c[k++]=a[i++];
}
else c[k++]=b[j++];
}
while(i<m)
{
Department of Computer Science and Engineering
Bangladesh University of Professionals
Mirpur Cantonment, Dhaka-1216
Page 7 of
8
c[k++]=b[i++];
}
while(j<n)
{
c[k++]=b[j++];
}
for(int i=0; i<m+n; i++)
{
printf("%d ",c[i]);
}
}
Output: