0% found this document useful (0 votes)
23 views8 pages

SPL Lab 8

Uploaded by

alajoshim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views8 pages

SPL Lab 8

Uploaded by

alajoshim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Lab Number# 08

Course title: Structured Programming Language Laboratory


Course code: CSE-1204
Session: July-December 2024

Date of Submission: 30/12/2024

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

Sl Class Roll Name

01 24524203135 MD. Akimo Islam Sad

Department of Computer Science and Engineering


Bangladesh University of Professionals
Mirpur Cantonment, Dhaka-1216
Problem Number: 01

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];

printf("Enter the elements \n");

for(int i=0; i<R; i++)

for(int j=0; j<C; j++)

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

printf("Sum Of the Column = ");

Department of Computer Science and Engineering


Bangladesh University of Professionals
Mirpur Cantonment, Dhaka-1216
Page 2 of
8
for(int j=0; j<C; j++)

sum[j]=0;

for(int i=0; i<R; i++)

sum[j]+=arr[i][j];

for(int j=0;j<C;j++){

printf("%d\n",sum[j]);

Output:

Department of Computer Science and Engineering


Bangladesh University of Professionals
Mirpur Cantonment, Dhaka-1216
Page 3 of
8
Problem Number: 02

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);
}
}

Department of Computer Science and Engineering


Bangladesh University of Professionals
Mirpur Cantonment, Dhaka-1216
Page 4 of
8
Output:

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);

Department of Computer Science and Engineering


Bangladesh University of Professionals
Mirpur Cantonment, Dhaka-1216
Page 5 of
8
while(N>0)
{
int number=N%10;
frq[number]++;

N=N/10;
}
for(int i=0;i<10;i++){
printf("%d",frq[i]);
}

Output:

Department of Computer Science and Engineering


Bangladesh University of Professionals
Mirpur Cantonment, Dhaka-1216
Page 6 of
8
Problem Description:
Write a C program to input two integers M, N, representing the number of elements in the arrays.
Then input M sorted integers and store them in an array named arr, and input N sorted integers and
store them in an array named brr. Finally, merge the elements of both arrays in sorted order into array
named crr and print crr .

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:

Department of Computer Science and Engineering


Bangladesh University of Professionals
Mirpur Cantonment, Dhaka-1216
Page 8 of
8

You might also like