You are on page 1of 6

22CSH-101_INTRODUCTION

TO PROBLEM SOLVING
Student name: Abhishek Pathak
section/group: 22 BCS-106_B
UID : 22BCS16643 Subject: Introduction to problem solving
Date: 30 NOV 2022
Branch: BE-CSE
Aim
1. To illustrate the concept of call by value vs. call by reference by taking example of
swapping of two numbers.
2. To write a recursive function for computing factorial of a number.
3. To write a program to read an array of elements and print the same in the reverse order
along with their addresses.
4. Write a function code that is returning pointer to the larger value out of two passes values.

Task to be done
Open GDB compiler and use the correct looping statement to execute the program.

Requirements
Online GDB compiler
Laptop

Input code:
1.1
#include <stdio.h>
void swapx(int x, int y);
int main()
{
int a = 39, b = 20;
swapx(a, b);
printf("a=%d b=%d\n", a, b);
return 0;
}
22CSH-101_INTRODUCTION
TO PROBLEM SOLVING
void swapx(int x, int y)
{
int t;
t = x;
x = y;
y = t;
printf("x=%d y=%d\n", x, y);
}

1.2
#include <stdio.h>
void swapx(int*, int*);
int main()
{
int a = 10, b = 20;
swapx(&a, &b);
printf("a=%d b=%d\n", a, b);
return 0;
}
void swapx(int* x, int* y)
{
int t;
t = *x;
*x = *y;
*y = t;
printf("x=%d y=%d\n", *x, *y);
}

2.
#include<stdio.h>
int main()
{
22CSH-101_INTRODUCTION
TO PROBLEM SOLVING
int i,fact=1,number;
printf("Enter a number: ");
scanf("%d",&number);
for(i=1;i<=number;i++){
fact=fact*i;
}
printf("Factorial of %d is: %d",number,fact);
return 0;
}

3.
#include<stdio.h>
void main() {
int size, i, arr[30];
int *ptr;
ptr = &arr[0];
printf("\nEnter the size of array : ");
scanf("%d", &size);
printf("\nEnter %d integers into array: ", size);
for (i = 0; i < size; i++) {
scanf("%d", ptr);
ptr++;
}
ptr = &arr[size - 1];
printf("\nElements of array in reverse order are :");
for (i = size - 1; i >= 0; i--) {
printf("\nElement%d is %d : ", i, *ptr);
ptr--;
}
}

4.
22CSH-101_INTRODUCTION
TO PROBLEM SOLVING
#include<stdio.h>
void main() {
int size, i, arr[30];
int *ptr;
ptr = &arr[0];
printf("\nEnter the size of array : ");
scanf("%d", &size);
printf("\nEnter %d integers into array: ", size);
for (i = 0; i < size; i++) {
scanf("%d", ptr);
ptr++;
}
ptr = &arr[size - 1];
printf("\nElements of array in reverse order are :");
for (i = size - 1; i >= 0; i--) {
printf("\nElement%d is %d : ", i, *ptr);
ptr--;
}
}

Simulation Results:
1.1

1.2
22CSH-101_INTRODUCTION
TO PROBLEM SOLVING

2.

3.

4.
22CSH-101_INTRODUCTION
TO PROBLEM SOLVING
Concept used
1.Concept of concept of call by value vs. call by reference is used by using
index values.
2.Finding factorial using C program.
3. Concept of pointers and its use.

Learning/ observation
Learnt the use of pointers.
Learnt the concept of call by reference and call by value.
And also learnt how to find the factorial.

Troubleshooting
Using the correct index and functions.

Learning outcomes (What I have learnt):


1. Use of call by reference and call by value.
2. Use of pointers.
3. Factorials.

Sr. No. Parameters Maximum Marks Marks


Obtained
1. Worksheet completion including writing learning 8
objectives/Outcomes.(To be submitted at the end of
the day).
2. Viva Voce 10

3. Student Engagement in 12
Simulation/Demonstration/Performance and
Controls/Pre-Lab Questions.
Signature of Faculty (with Date): Total Marks
Obtained:

You might also like