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

Bangladesh University of and Technology: Business

This document contains 6 programming questions and their solutions involving arrays in C language. The questions include: 1) Summing all elements of an array, 2) Adding values at specified positions of two arrays, 3) Printing an array in reverse order, 4) Multiplying all elements of an array by a given value, 5) Dividing all elements of an array by a given value, 6) Swapping two elements of an array. For each question, the C code for the solution is provided along with an output section. The document appears to be an assignment submitted by a student to their instructor for a structured programming lab course.

Uploaded by

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

Bangladesh University of and Technology: Business

This document contains 6 programming questions and their solutions involving arrays in C language. The questions include: 1) Summing all elements of an array, 2) Adding values at specified positions of two arrays, 3) Printing an array in reverse order, 4) Multiplying all elements of an array by a given value, 5) Dividing all elements of an array by a given value, 6) Swapping two elements of an array. For each question, the C code for the solution is provided along with an output section. The document appears to be an assignment submitted by a student to their instructor for a structured programming lab course.

Uploaded by

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

Bangladesh University of Business

and Technology

BUBT
Committed to Academic Excellence

Assingment No-02

Course Title: Structured Programming Language(Lab)


Course Code: CSE 102

SUBMITTED TO:
Partho Ghose SUBMITTED BY
Lecturer

Department of CSE Sadman Ishraq

Performance Date: 20/09/2022 ID:22234103212

Intake: 50th , Sec: 06


Submission Date: 18 /10/2022
Q1. Array clement Summation:

1. #include <stdio.h>
2. int main () {
3. int a[5], sum=0;
4. printf("Enter Array Elements: ");
5. for(int i=0; i<5; i++)
6. {
7. scanf("%d",&a[i]);
8. }
9. printf("Sum of Array Element: ");
10. for( int i=0; i<5; i++)
11. {
12. sum=sum+a[i];
13. }
14. printf("%d",sum);
15. return 0;
16.}

Output:
Q2. Add the value of the specified position of 2 arrays.

1. #include<stdio.h>
2. int main(){
3. int p,q,i,j,sum=0,n,m;
4. printf("enter the value of p:");
5. scanf("%d",&p);
6. printf("\nenter the value of q:");
7. scanf("%d",&q);
8. int a[p];
9. int b[q];
10. printf("\nenter the array a:");
11.for (i = 0; i < p; i++)
12.{
13. scanf("%d",&a[i]);
14.}
15. printf("\nenter the array b:");
16.for (j = 0; j < q; j++)
17.{
18. scanf("%d",&b[j]);
19.}
20. printf("\nposition of a array:");
21. scanf("%d",&n);
22. printf("\nposition of b array:");
23. scanf("%d",&m);
24.sum=a[n]+b[m];
25.printf("\nthe result of sum is :%d",sum);
26.return 0;
27.}

Output:
Q3. Array reverse to print:

1. #include<stdio.h>
2.
3. #define N 5
4. int main ()
5. {
6. int a[N];
7. printf("Enter %d integer number: \n",N);
8. for(int i=0;i<N;i++)
9. scanf("%d",&a[i]);
10. printf("Elements of array reverse: \n");
11. for(int i=N-1;i>=0;i--)
12. printf("%d\n",a[i]);
13. return 0;
Output:

Q4. Array multiplication by some value.

1. #include<stdio.h>
2. int main(){
3. int i,m,q;
4. printf("enter the length of array:");
5. scanf("%d",&q);
6. printf("\n");
7. int a[q];
8. for ( i = 0; i < q; i++)
9. {
10. scanf("%d",&a[i]);
11. }
12. for ( i = 0; i < q; i++)
13. {
14. printf("nenter the multiplication value:");
15. scanf("%d",&m);
16. printf("\n");
17.
18. a[i] = a[i]* m;
19. }
20. for ( i = 0; i < q; i++)
21. {
22. printf("%d\n",a[i]);
23. }
24.
25.}
Output:

Q5. Array division by some value.

1. #include<stdio.h>
2. int main(){
3. int i,m,q;
4. printf("enter the length of array:");
5. scanf("%d",&q);
6. printf("\n");
7. int a[q];
8. for ( i = 0; i < q; i++)
9. {
10. scanf("%d",&a[i]);
11. }
12. for ( i = 0; i < q; i++)
13. {
14. printf("\nenter the multiplication value:");
15. scanf("%d",&m);
16. printf("\n");
17.
18. a[i] = a[i] / m;
19. }
20. for ( i = 0; i < q; i++)
21. {
22. printf("%d\n",a[i]);
23. }
24.}
Output:

Q6. Array element swap:

1. #include<stdio.h>
2. int main(){
3. int a,b;
4. printf("Enter One Number A: ");
5. scanf("%d",&a);
6. printf("Enter Two Number B: ");
7. scanf("%d",&b);
8. a=a+b;
9. b=a-b;
10. a=a-b;
11. printf("a=%d\n",a);
12. printf("b=%d",b);
13. return 0;
14.}

Output:

You might also like