Index: S.No Name of Practical Remarks S.No
Index: S.No Name of Practical Remarks S.No
Index: S.No Name of Practical Remarks S.No
23 Write a program to swap two integers using call by value and call by
reference methods of passing arguments to a function.
As we studied earlier, ‘C’ is a base language for many programming languages. So,
learning ‘C’ as the main language will play an important role while studying other
programming languages. It shares the same concepts such as data types, operators,
control statements and many more. ‘C’ can be used widely in various applications. It is a
simple language and provides faster execution. There are many jobs available for a ‘C’
developer in the current market.
‘C’ is a structured programming language in which program is divided into various
modules. Each module can be written separately and together it forms a single ‘C’
program. This structure makes it easy for testing, maintaining and debugging processes.
‘C’ contains 32 keywords, various data types and a set of powerful built-in functions that
make programming very ef cient.
Another feature of ‘C’ programming is that it can extend itself. A ‘C’ program contains
various functions which are part of a library. We can add our features and functions to the
library. We can access and use these functions anytime we want in our program. This
feature makes it simple while working with complex programming.
fl
fi
Various compilers are available in the market that can be used for executing programs
written in this language.
It is a highly portable language which means programs written in ‘C’ language can run on
other machines. This feature is essential if we wish to use or execute the code on another
computer.
Getting Dev-C++
The author has released Dev-C++ as free software (under GPL) but also offers a CD
for purchase which can contain all Bloodshed software (it's customizable), including
Dev-C++ with all updates/patches.
You should let the installer put Dev-C++ in the default directory of C:\Dev-Cpp, as it
will make it easier to later install add-ons or upgrades.
Using Dev-C++
This section is probably why you are here.
All programming done for CSCI-2025 will require separate compilation projects (i.e.
class header le(s), class implementation le(s) and a main/application/client/driver
le). This process is relatively easy as long as you know what Dev-C++ requires to
do this. In this page you will be given instructions using the Project menu choice. In
another handout you will be given instructions on how to manually compile, link and
execute C++ les at the command prompt of a command window. See here.
• Click "OK".
• Go to the "File" menu and select "New Source File" (or just press
CTRL+N) OR
• Go to the "Project" menu and select "New File".
Note that Dev-C++ will not ask for a lename for any new source le until you
attempt to:
1. Compile
2. Save the project
3. Save the source le
4. Exit Dev-C++
•
You can add pre-existing source les one of two ways:
• Go to the "Project" menu and select "Add to Project" OR
• Right-click on the project name in the left-hand panel and select "Add to
Project".
EXAMPLE: Multiple source files
In this example, more than 3 files are required to compile the program; The "driver.cpp" file references "Deque.h" (which
requires "Deque.cpp") and "Deque.cpp" references "Queue.h" (which requires "Queue.cpp").
fi
fi
fi
fi
fi
fi
fi
fi
Step 4: Compile.
Once you have entered all of your source code, you are ready to compile.
•
• Method 2 - Scaffolding:
Add the following code before any return statement in main() or
any exit() or abort() statement (in any function):
/* Scaffolding code for testing purposes */
• cin.ignore(256, '\n');
• cout << "Press ENTER to continue..." << endl;
• cin.get();
• /* End Scaffolding */
•
This will give you a chance to view any output before the program terminates
and the window closes.
fi
fl
fl
fi
• Method 3 - Command-prompt:
Alternatively, instead of using Dev-C++ to invoke your program, you can just
open an MS-DOS Prompt, go to the directory where your program was
compiled (i.e. where you saved the project) and enter the program name (along
with any parameters). The command-prompt window will not close when the
program terminates.
For what it's worth, I use the command-line method.
Step 6: Debug.
When things aren't happening the way you planned, a source-level debugger can be a
great tool in determining what really is going on. Dev-C++'s basic debugger
functions are controlled via the "Debug" tab at the bottom of the screen; more
advanced functions are available in the "Debug" menu.
#include <stdio.h>
int main() {
return 0;
}
Output :-
C) WAP to show the sum of three numbers.
Code :-
#include <stdio.h>
int main()
{
int x, y, z, sum;
scanf("%d%d%d",&x,&y,&z);
sum=x+y+z;
printf("\n Sum of Three Number is = %d", sum);
return 0;
Output :-
D) WAP to compute the Ascii value of a character
Code :-
#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
scanf("%c", &c);
return 0;
}
Output :-
Practical - 2
A) WAP to take multiple inputs from the user
Code :-
#include <stdio.h>
int main()
{
oat num1;
double num2;
return 0;
}
Output :-
fl
B) WAP to use getchar() and putchar() functions
Code :-
#include <stdio.h>
#include <stdlib.h>
main( )
{
char ch;
char s[10];
int i=0;
printf("Enter a number or string\n");
while((ch=getchar())!='\n')
{
s[i]=ch;
i++;
}
printf("Original Number/String: %s\n",s);
printf("Reverse Number/String: ");
while(--i>=0)
{
putchar(s[i]);
}
return 0;
}
Output :-
C). WAP to use gets() and puts() functions.
Code :-
#include<stdio.h>
#include <string.h>
void main()
{
char day[10];
printf("Enter current week day: \n");
gets(day);
printf("Today is: ");
puts(day);
}
Output :-
Practical - 3
Pseudocode :
Algorithm :
Pseudocode :
• Input the width (W) and length (L) of a rectangle
• Calculate the area (a) by multiplying L with B
• Print A
Algorithm :
Step 1: input B,L
Step 2 : A= L X B
Step 3 : print A
fl
Practical - 4
Code :-
#include <stdio.h>
int main(void) {
int i,max,min,N,x;
printf("Enter N : ");
scanf("%d",&N);
max=0;
min=999;
for(i=1;i<=N;i++)
scanf("%d",&x);
if(max < x)
max = x;
if(min > x)
min = x;
return 0;
Output :-
fi
Practical - 5
Code :-
#include<stdio.h>
int main()
{
int score;
switch( score / 10 )
{
case 10:
case 9:
printf("Grade: A");
break;
case 8:
printf("Grade: B");
break;
case 7:
printf("Grade: C");
break;
case 6:
printf("Grade: D");
break;
fi
fi
case 5:
printf("Grade: E");
break;
default:
printf("Grade: F");
break;
return 0;
}
Output :-
Practical - 6
Code :-
#include <stdio.h>
int main()
int week;
scanf("%d", &week);
switch(week)
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
case 4:
printf("Thursday");
break;
case 5:
printf("Friday");
break;
case 6:
printf("Saturday");
break;
case 7:
printf("Sunday");
break;
default:
return 0;
Output :-
Practical - 7
Code :-
#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
Output :-
Practical - 8
Code :-
#include <stdio.h>
int main()
{
int unit;
oat amt, total_amt, sur_charge;
/*
* Calculate total electricity bill
* after adding surcharge
*/
sur_charge = amt * 0.20;
total_amt = amt + sur_charge;
return 0;
}
Output :-
Practical - 9
WAP to Check Whether a Number is Prime or not.
Code :-
#include <stdio.h>
int main() {
int n, i, ag = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
if (n == 0 || n == 1)
ag = 1;
return 0;
}
Output :-
fl
fl
fl
fl
Practical - 10
WAP to print positive integers from 1 to 10
Code :-
#include<stdio.h>
int main()
{
int Size, i, a[10];
Code :-
#include <stdio.h>
int main() {
int i, n;
int t1 = 0, t2 = 1;
return 0;
}
Output :-
Practical - 12
WAP to reverse a given integer .
Code :-
#include <stdio.h>
int main() {
while (n != 0) {
remainder = n % 10;
reverse = reverse * 10 + remainder;
n /= 10;
}
return 0;
}
Output :-
Practical - 13
WAP to check whether a number is Palindrome or not
Code :-
#include <stdio.h>
int main() {
int n, reversed = 0, remainder, original;
printf("Enter an integer: ");
scanf("%d", &n);
original = n;
while (n != 0) {
remainder = n % 10;
reversed = reversed * 10 + remainder;
n /= 10;
}
if (original == reversed)
printf("%d is a palindrome.", original);
else
printf("%d is not a palindrome.", original);
return 0;
}
Output :-
Practical - 14
WAP to calculate factorial of a number using recursion
and iteration method.
Code :-
#include<stdio.h>
long int fact(int n);
long int Ifact(int n);
int main( )
{
int num;
printf("Enter a number : ");
scanf("%d", &num);
if(num<0)
printf("No factorial for negative number\n");
else
printf("Factorial of %d is %ld\n", num, Ifact(num) );
return 0;
}/*End of main()*/
/*Recursive*/
long int fact(int n)
{
if(n == 0)
return(1);
return(n * fact(n-1));
}/*End of fact()*/
/*Iterative*/
long int Ifact(int n)
{
long fact=1;
while(n>0)
{
fact = fact*n;
n--;
}
return fact;
}/*End of ifact()*/
Output :-
Practical - 15
WAP to print the triangle of stars as follows (take
number of lines from user)
*
**
* **
* ** *
Code :-
#include <stdio.h>
int main() {
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i) {
for (j = 1; j <= i; ++j) {
printf("* ");
}
printf("\n");
}
return 0;
}
Output :-
Practical - 16
Code :-
#include <stdio.h>
int main()
{
int arr[100] = { 0 };
int i, x, pos, n = 10;
x = 50;
pos = 5;
n++;
arr[pos - 1] = x;
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
return 0;
}
Output :-
Practical - 17
Code :-
#include <stdio.h>
#include <stdlib.h>
#de ne n 6
int main(){
int arr[n] = {9, 8, 7, 2, 4, 3};
int temp;
for(int i = 0; i<n/2; i++){
temp = arr[i];
arr[i] = arr[n-i-1];
arr[n-i-1] = temp;
}
for(int i = 0; i < n; i++){
printf("%d,", arr[i]);
}
}
Output :-
fi
Practical - 18
WAP to Display Max Element of an array.
Code :-
#include <stdio.h>
int main() {
int n;
double arr[100];
scanf("%d", &n);
scanf("%lf", &arr[i]);
arr[0] = arr[i];
return 0;
Output :-
Practical - 19
WAP to access an element in 2-D Array.
Code :-
#include<stdio.h>
int main() {
int i, j, a[3][3];
}
}
}
printf("\n");
}
return (0);
Output :-
Practical - 20
Code :-
#include<stdio.h>
int main()
{
int a[10][10],r,c,sum=0,i,j;
printf("/*How Many Rows You Want To \nEnter in Matrix*/\nEnter Limit : ");
scanf("%d",&r);
printf("\n/*How Many Columns You Want To \nEnter in Matrix*/\nEnter Limit :
");
scanf("%d",&c);
printf("\nEnter Elements for Matrix of Size %d*%d:\n\n",r,c);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n%d*%d Matrix : \n\n",r,c);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%2d ",a[i][j]);
}
printf("\n");
}
for(i=0;i<r;i++)
for(j=0;j<c;j++)
sum=sum+a[i][j];
printf("\nSum of All Elements in Matrix = %d",sum);
return 0;
fi
}
Output :-
Practical - 21
Code :-
#include <stdio.h>
int main()
{
int m,n;
printf("Enter the number of rows and column: \n");
scanf("%d %d",&m,&n);
int arr[10][10];
printf("\nEnter the elements of the matrix: \n");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
scanf("%d",&arr[i][j]);
}
}
printf("\nThe elements in the matrix are: \n");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
printf("%d ",arr[i][j]);
}
printf("\n");
}
int brr[10][10];
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
fi
{
brr[j][i]=arr[i][j]; //Store elements in the transpose matrix
}
}
printf("\nAfter transpose the elements are...\n");
for(int i=0;i<m;i++) //Print the transpose matrix
{
for(int j=0;j<n;j++)
{
printf("%d ",brr[i][j]);
}
printf("\n");
}
return 0;
}
Output :-
Practical - 22
Code :-
#include <stdio.h>
printf("\nOutput Matrix:\n");
for (int i = 0; i < row; ++i) {
for (int j = 0; j < column; ++j) {
printf("%d ", result[i][j]);
if (j == column - 1)
printf("\n");
}
}
}
int main() {
int rst[10][10], second[10][10], result[10][10], r1, c1, r2, c2;
printf("Enter rows and column for the rst matrix: ");
scanf("%d %d", &r1, &c1);
printf("Enter rows and column for the second matrix: ");
scanf("%d %d", &r2, &c2);
return 0;
}
fi
fi
fi
fi
Output :-
Practical - 23
Code :-
#include <stdio.h>
int temp;
temp = num1;
num1 = num2;
num2 = temp;
int main()
swap(n1, n2);
return 0;
Output :-
Practical - 24
Code :-
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char str1[20],str2[20];
int ch,i,j;
do
{
printf("\tMENU");
printf("\n------------------------------\n");
printf("1:Find Length of String");
printf("\n2:Concatenate Strings");
printf("\n3:Compare Strings");
printf("\n4:Exit");
printf("\n------------------------------\n");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("Enter String: ");
scanf("%s",str1);
i=strlen(str1);
printf("Length of String : %d\n\n",i);
break;
case 2:
printf("\nEnter First String: ");
scanf("%s",str1);
printf("Enter Second string: ");
scanf("%s",str2);
strcat(str1,str2);
printf("String After Concatenation : %s\n\n",str1);
break;
case 5:
printf("Enter First String: ");
scanf("%s",str1);
printf("Enter Second String: ");
scanf("%s",str2);
j=strcmp(str1,str2);
if(j==0)
{
printf("Strings are Same\n\n");
}
else
{
printf("Strings are Not Same\n\n");
}
break;
case 4:
exit(0);
break;
default:
printf("Invalid Input. Please Enter valid Input.\n\n ");
}
}while(ch!=6);
return 0;
}
Output :-
Practical - 25
Code :-
#include <stdio.h>
struct student {
char rstName[50];
int roll;
oat marks;
} s[5];
int main() {
int i;
printf("Enter information of students:\n");
// storing information
for (i = 0; i < 5; ++i) {
s[i].roll = i + 1;
printf("\nFor roll number%d,\n", s[i].roll);
printf("Enter rst name: ");
scanf("%s", s[i]. rstName);
printf("Enter marks: ");
scanf("%f", &s[i].marks);
}
printf("Displaying Information:\n\n");
// displaying information
for (i = 0; i < 5; ++i) {
printf("\nRoll number: %d\n", i + 1);
fl
fi
fi
fi
printf("First name: ");
puts(s[i]. rstName);
printf("Marks: %.1f", s[i].marks);
printf("\n");
}
return 0;
}
Output :-
fi
Practical - 26
Create a file that contains records of 5 employees. Each record
contains an employee’s
salary details. Print the information retrieved from the file in
the following format: Employee id Name Basic HRA DA
ExtraAllowances
Code :-
#include <stdio.h>
int main() {
char id[10];
int hour;
double value, salary;
scanf("%d", &hour);
printf("\nSalary amount/hr: “);
scanf("%lf", &value);
salary = value * hour;
printf("\nEmployees ID = %s\nSalary = U$ %.2lf\n", id,salary);
return 0;
}
Output :-