You are on page 1of 80

VANSHIKA

Practical file submitted in partial


fulfillment for the evaluation of

“Programming in C-Lab”

Submitted By:
Student Name: Vikram Ranjan
Enrolment no: 09917711922
Branch & Section: AIDS (B)

Submitted To:
• Dr. Deepika Bhatia
VANSHIKA

Index
S.No Experiment Title Page Date Grade/ Sign
(GGSIPU) No. Evaluation
VANSHIKA

Index
S.No Experiment Title Page Date Grade/ Sign
(Beyond Curriculum) No. Evaluation
VANSHIKA

SECTION 1

BEYOND CURRICULUM
VANSHIKA

EXPERIMENT 1
Problem statement:
Write an algorithm that reads the two numbers and print the value of the
largest number. Also draw the flowchart using Flowgorithm.

Algorithm :

Flowchart and Pseudocode with output:


Flowchart
VANSHIKA

Pseudocode

Output
VANSHIKA

Programming Code:

Output:

Learning Outcomes :
VANSHIKA

EXPERIMENT 2
Problem statement:

Write an algorithm and draw a flowchart to find the sum of two numbers

Algorithm :

Flowchart and Pseudocode with output:


Flowchart
VANSHIKA

Pseudocode:

Output
VANSHIKA

Programming Code:

Output

Learning Outcomes :
VANSHIKA

EXPERIMENT 3
Problem statement:
Write a C program to print Hello world. Also draw the flowchart using
Flowgorithm.
Algorithm :

Flowchart and Pseudocode with output:


Flowchart:

Pseudocode:
VANSHIKA

Output

Programming Code:

Output

Learning Outcomes :
VANSHIKA

EXPERIMENT 4
Problem statement:

Write a program and draw a flowchart to check whether a number is even or odd.

Algorithm :

Flowchart and Pseudocode with output:


Flowchart:
VANSHIKA

Pseudocode:

Output
VANSHIKA

Programming Code:

Output

Learning Outcomes :
VANSHIKA

EXPERIMENT 5
Problem statement:

10% discount is given, when a customer buys more than 100 items. Item cost will be entered
by the user. Write an algorithm to calculate the final cost that has to be paid. Also draw the
flowchart using flowgorithm.

Algorithm :

Flowchart and Pseudocode with output:


Pseudocode
VANSHIKA

Flowchart:

Output
VANSHIKA

Programming Code:

Output

Learning Outcomes
VANSHIKA

EXPERIMENT 6
Problem statement:
Write a C Program to print pyramid of *.
Algorithm :

Flowchart and Pseudocode with output:


Flowchart
VANSHIKA

Pseudocode

Output
VANSHIKA

Programming Code:

Output

Learning Outcomes
VANSHIKA

EXPERIMENT 7
Problem statement:
Write a C program to print inverted pyramid of * .
Algorithm :

Flowchart and Pseudocode with output:


Flowchart
VANSHIKA

Pseudocode

Output
VANSHIKA

Programming Code:

Output

Learning Outcomes
VANSHIKA

EXPERIMENT 8
Problem statement:
A) Write a C program to understand the concept of continue statement and
calculate sum of numbers. Also draw the flowchart of the given program. If a
user enters a negative number, it is not added into result
Algorithm :

Flowchart and Pseudocode with Output:


Pseudocode
VANSHIKA

Flowchart

Output
VANSHIKA

Programming Code:

Output

Learning Outcomes
VANSHIKA

EXPERIMENT 8

Problem statement:
B) Write a C program to convert decimal number to binary number.
Algorithm :

Programming Code:
VANSHIKA

Output

Learning Outcomes
VANSHIKA

EXPERIMENT 9

Problem statement:
Write a C program to find sum of numbers and average of all numbers using arrays

Algorithm :

Flowchart and Pseudocode with Output:


Pseudocode
VANSHIKA

Flowchart
VANSHIKA

Output

Programming Code:
VANSHIKA

Output

Learning Outcomes
VANSHIKA

EXPERIMENT 10

Problem statement:
Write a C program to find sum of Natural numbers using recursion.
Algorithm :

Programming Code:
VANSHIKA

Output

Learning Outcomes
VANSHIKA

EXPERIMENT 11

Problem statement:
Write a C program to understand the concept of call by value and call by
reference.
Algorithm :

Programming Code:
include<stdio.h>
int swap1(int,int) ;
int swap2(int*,int*) ;
int main()
{
int num1, num2 ;
num1 = 10 ;
num2 = 20 ;
printf("Swaping through call by value\n") ;
printf("\nBefore swap: num1 = %d , num2 = %d", num1, num2) ;
swap1(num1, num2) ;
printf("\nAfter swap in main: num1 = %d , num2 = %d\n", num1, num2) ;
printf("\nSwaping through call by reference\n") ;
VANSHIKA

printf("\nBefore swap: num1 = %d , num2 = %d", num1, num2) ;


swap2(&num1, &num2) ;
printf("\nAfter swap in main: num1 = %d , num2 = %d", num1, num2);
return 0;
}
int swap1(int a, int b)
{
int temp ;
temp = a ;
a=b;
b = temp ;
printf("\nAfter swap in function: num1 = %d , num2 = %d", a, b);
return 0;
}
int swap2(int* a, int* b)
{
int temp ;
temp = *a ;
*a = *b ;
*b = temp ;
printf("\nAfter swap in function: num1 = %d , num2 = %d", *a, *b);
return 0;
}
VANSHIKA

Output

Learning Outcomes
VANSHIKA

EXPERIMENT 12

Problem statement:

Write a C program to store information of 5 students by using an array of


structures.

Programming Code:
#include<stdio.h>

struct student {

char name[20];

int rollno;

float marks;

};

int main(){

int i,n;

printf("Enter how many records u want to store :: ");

scanf("%d",&n);

struct student stuArr[n];

printf("Enter name, roll no. and marks Below :: \n");

for(i=0; i<n; i++){

printf("\nEnter %d record :: \n", i+1);

printf("Enter Name :: ");

scanf("%s",stuArr[i].name); printf("Enter RollNo.:: ");

scanf("%d", &stuArr[i].rollno);

printf("Enter Marks :: ");

scanf("%f",&stuArr[i].marks);

printf("\nName:RollNo:Marks:\n");

for(i=0; i<n; i++) {

printf("%s:%d:%.2f:\n", stuArr[i].name, stuArr[i].rollno, stuArr[i].marks);

return 0; }
VANSHIKA

Output

Learning Outcomes
VANSHIKA

SECTION 2

GGSIPU
VANSHIKA

EXPERIMENT 1
Problem statement:

Write a program to find divisor or factorial of a given number.

Algorithm :

Flowchart and Pseudocode with output:


Flowchart:
VANSHIKA

Pseudocode:

Output
VANSHIKA

Programming Code:

Output:

Learning Outcomes
VANSHIKA

EXPERIMENT 2
Problem statement:
Write a program to find sum of geometric series.

Algorithm :

Flowchart and Pseudocode with output:


Flowchart:
VANSHIKA

Pseudocode:
VANSHIKA

Output

Programming Code:

Output
VANSHIKA

Learning Outcomes
VANSHIKA

EXPERIMENT 3
Problem statement:
Write recursive program to print the first m Fibonacci number.

Algorithm :

Programming Code:
#include<stdio.h>
int fabonacci(int);
int main()
{
int i,n,result;
printf("Enter the number to find fabonacci series : ");
scanf("%d",&n);
printf("Fabonacci series :\n ");
for(i=1;i<=n;i++)
{
result=fabonacci(i);
printf(" %d ",result);
}

return 0;
}

int fabonacci (int a)


{
int fab;
if(a==1)
return 0;
else if(a==2)
VANSHIKA

return 1;
else
fab=fabonacci(a-1)+fabonacci(a-2);
}

Output

Learning Outcomes
VANSHIKA

EXPERIMENT 4
Problem statement:

Write a menu driven program for matrices to do the following operations


depending on whether the operations require one or two matrices .

Addition of 2 Matrices
Subtraction of 2 Matrices
Finding upper and lower triangular Matrices
Transpose of a Matrix
Product of 2 Matrices

Algorithm :

Flowchart and Pseudocode with output:

Programming Code:
#include<stdio.h>
int main()
{
int op;
int row1,col1,k,l,b[10][10],sub[10][10],row,col,i,j,a[10][10];
int mul[10][10],tran[10][10],up[10][10],low[10][10],add[10][10];
printf("Type digits to perform respective operations : \n");
printf("1:Addition\n2:Multiply\n3:Transpose\n4:Subtraction\n5:Upper & Lower
Triangle:\n ");
scanf("%d",&op);
switch(op)
{
case 1:

printf("Enter first matrix\n");


printf("Enter column of matrics : ");
scanf("%d",&col);
VANSHIKA

printf("Enter row of matrics : ");


scanf("%d",&row);
//scaning first matrix
printf("");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("Enter value of element a[%d][%d] :",i,j);
scanf("%d",&a[i][j]);
}
}
//printing first matrix
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n") ;
}
printf("\n") ;
printf("Enter second matrix\n");
printf("Enter column of matrics : ");
scanf("%d",&col1);
printf("Enter row of matrics : ");
scanf("%d",&row1);
for(k=0;k<row1;k++)
{
for(l=0;l<col1;l++)
VANSHIKA

printf("Enter value of element a[%d][%d] :",k,l);


scanf("%d",&b[k][l]);
}
}
//printing second marix
for(k=0;k<row1;k++)
{
for(l=0;l<col1;l++)
{
printf("%d\t",b[k][l]);

}
printf("\n") ;
}
printf("\n") ;
//ADDITION
if(row==row1&&col==col1)
{
for (i = 0; i < row; i++)
for (j = 0; j < col; j++)
{
add[i][j] = a[i][j] + b[i][j];
}
printf("Addition of two matrices: \n");
for (i = 0; i < row; i++)
for (j = 0; j < col; j++)
{
printf("%d ", add[i][j]);
VANSHIKA

if (j == col - 1)
{
printf("\n");
}
}
}
else{printf("Please enter equal number of rows and columns to add two matrices") ; }
break;

case 2:
printf("Multiplication of the matrices\n");
printf("Enter first matrix\n");
printf("Enter column of matrics : ");
scanf("%d",&col);
printf("Enter row of matrics : ");
scanf("%d",&row);
printf("Enter first matrix\n");
//scaning first matrix

printf("");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++){

printf("Enter value of element a[%d][%d] :",i,j);


scanf("%d",&a[i][j]);
}
}
printf("\n") ;
printf("Enter second matrix\n");
VANSHIKA

printf("Enter column of matrics : ");


scanf("%d",&col1);
printf("Enter row of matrics : ");
scanf("%d",&row1);
for(k=0;k<row1;k++)
{
for(l=0;l<col1;l++)
{

printf("Enter value of element a[%d][%d] :",k,l);


scanf("%d",&b[k][l]);
}
}
//multiplication
printf("Multiplication of given two matrices : \n");
for(i=0;i<row;i++)
{
for(j=0;j<col1;j++)
{
mul[i][j]=0;
for(k=0;k<col1;k++)
{
mul[i][j]+=a[i][k]*b[k][j];
}
}
}
//for printing result
for(i=0;i<row;i++)
{
for(j=0;j<col1;j++)
VANSHIKA

{
printf("%d\t",mul[i][j]);
}
printf("\n");
}
break;

case 3:

printf("Enter first matrix\n");


printf("Enter column of matrics : ");
scanf("%d",&col);
printf("Enter row of matrics : ");
scanf("%d",&row);
//scaning first matrix
printf("");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++){

printf("Enter value of element a[%d][%d] :",i,j);


scanf("%d",&a[i][j]);
}
}
//printing first matrix
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",a[i][j]);
VANSHIKA

}
printf("\n") ;
}
printf("\n") ;
for ( i = 0; i < row; ++i)
{
for ( j = 0; j < col; ++j)
{
tran[j][i] = a[i][j];
}
}
printf("\nTranspose of the matrix:\n");
for (i = 0; i < col; i++)
for (j = 0; j < row; j++)
{
printf("%d ", tran[i][j]);
if (j == row - 1)
{
printf("\n");
}
}
break;

case 4:

printf("Enter column of matrics : ");


scanf("%d",&col);
printf("Enter row of matrics : ");
scanf("%d",&row);
printf("Enter first matrix\n");
VANSHIKA

//scaning first matrix

for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("Enter value of element a[%d][%d] :",i,j);
scanf("%d",&a[i][j]);
}
}
//printing first matrix
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n") ;
}
printf("\n") ;
printf("Enter second matrix\n");
printf("Enter column of matrics : ");
scanf("%d",&col1);
printf("Enter row of matrics : ");
scanf("%d",&row1);
for(k=0;k<row1;k++)
{
for(l=0;l<col1;l++)
{
VANSHIKA

printf("Enter value of element a[%d][%d] :",k,l);


scanf("%d",&b[k][l]);
}
}
//printing second marix
for(k=0;k<row1;k++)
{
for(l=0;l<col1;l++)
{
printf("%d\t",b[k][l]);

}
printf("\n") ;
}
printf("\n") ;
//subtracting
if(row==row1&&col==col1)
{
for (i = 0; i < row; i++)
for (j = 0; j < col; j++)
{
sub[i][j] = a[i][j] - b[i][j];
}
printf("Subtraction of two matrices: \n");
for (i = 0; i < row; i++)
for (j = 0; j < col; j++)
{
printf("%d ", sub[i][j]);
if (j == col - 1)
{
VANSHIKA

printf("\n\n");
}
}
}
else{printf("Please enter equal number of rows and columns to add two matrices") ; }
break;

case 5:

printf("Enter the number of rows: ");


scanf("%d", &row);
printf("Enter the number of columns: ");
scanf("%d", &col);
//scaning
for(i = 0; i < row; i++)
{
for(j = 0;j < col;j++)
{
printf("Enter value of element a[%d][%d] : ",i,j);
scanf("%d", &a[i][j]);
}
}
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",a[i][j]);

}
printf("\n") ;
VANSHIKA

}
printf("The Lower Triangular Matrix is\n");
for(i = 0; i < row; i++)
{
for(j = 0;j < col; j++)
{
if(i >= j)
{
printf("%d\t",a[i][j]);
}
else
{
printf("0\t");
}
}
printf("\n") ;
}
printf("The Upper Triangular Matrix is\n");
for(i = 0; i < row; i++)
{
for(j = 0; j < col; j++)
{
if(i > j)
{
printf("0\t");
}
else
{
printf("%d\t",a[i][j]);
}
VANSHIKA

}
printf("\n") ;
}

break;
}
return 0;
}

Output
Addition
VANSHIKA

Multiplication

Transpose
VANSHIKA

Subtraction

Upper and Lower Triangular Matrix


VANSHIKA

EXPERIMENT 5

Problem statement:

Write a program to perform the following operators on Strings without using


String functions
To find the Length of String.
To concatenate the string.
To find Reverse of a string.
To copy one string to another string
Algorithm :
Flowchart and Pseudocode with output:

Programming Code:

#include<stdio.h>
int main()
{
int op,j,count;
printf("Type digits to perform respective operations on string: ") ;
printf("\n1:Length of string\n2:Concatination\n3:Copy string\n4:Reverse a string \n");
scanf("%d",&op);
switch(op)
{
case 1 :
{
char str[1000];
int i;
printf("Enter the String: ");
scanf("%s", str);
for (i = 0;str[i] != '\0'; ++i);
printf("Length of string is %d", i);
}
VANSHIKA

break;

case 2:

{
char str1[100],str2[100],str3[100];
int i,j;
printf("Enter the String: ");
scanf("%s", str1);
printf("Enter the String: ");
scanf("%s", str2);
i=0;
j=0;
while (str1[i] != '\0')
{
str3[j] = str1[i];
i++;
j++;
}
i = 0;
while (str2[i] != '\0')
{
str3[j] = str2[i];
i++;
j++;
}
str3[j] = '\0';
printf("\nConcatenated string: %s", str3);
}
break ;
VANSHIKA

case 3:
{
int i;
char str[100],copy_str[100];
printf("Enter string 1 : ") ;
scanf("%s",str);
printf("Enter string 2 : ") ;
scanf("%s",copy_str);
printf("String 2 before coping string 1 in it ; %s\n",copy_str);
for( i=0; str[i] != '\0'; i++)
{
copy_str[i] = str[i];
}
copy_str[i] = '\0';
printf("Copied string 2 = %s",copy_str);
}

break;

case 4:
{

char temp;
char str1[100];
int c=0;
int i;
printf (" Enter a string to be reversed: ");
scanf( "%s", str1);
while ( str1[c] != '\0')
VANSHIKA

c++;

printf("Length of the string: %d\n", c);


c--;
for(i=0;i<=c/2;i++)
{
temp=str1[i];
str1[i]=str1[c-i] ;
str1[c-i]=temp;

printf (" The reversed of the string: %s", str1);


}

break ;

}
return 0;
}

Output
Length
VANSHIKA

Concatenation

Copy string

Reverse string

Learning Outcomes
VANSHIKA

EXPERIMENT 6

Problem statement:

Write a recursive program for tower of Hanoi problem

Programming Code:
VANSHIKA

Output

Learning Outcomes
VANSHIKA

EXPERIMENT 7

Problem statement:

Write a program to copy one file to other, use command line arguments

Programming Code:
VANSHIKA

Output
VANSHIKA

EXPERIMENT 8

Problem statement:

An array of record contains information of managers and workers of a


company. Print all the data of managers and workers in separate files
Programming Code:
VANSHIKA
VANSHIKA

Output
VANSHIKA

EXPERIMENT 9

Problem statement:

Write a Program to store records of a student in student file. The data must be
stored using Binary File. Read the record stored in “Student.txt” file in
Binary code. Edit the record stored in Binary File. Append a record in the
student file
Programming Code:
VANSHIKA

Output
VANSHIKA

EXPERIMENT 10

Problem statement:

Write a programmed to count the no of Lowercase, Uppercase numbers and


special Characters presents in the contents of text File.

Programming Code:
VANSHIKA

Output

ORIGINAL FILE

You might also like