Vanshika Cprog
Vanshika Cprog
“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 :
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 :
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 :
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 :
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:
Output
VANSHIKA
Programming Code:
Output
Learning Outcomes
VANSHIKA
EXPERIMENT 6
Problem statement:
Write a C Program to print pyramid of *.
Algorithm :
Pseudocode
Output
VANSHIKA
Programming Code:
Output
Learning Outcomes
VANSHIKA
EXPERIMENT 7
Problem statement:
Write a C program to print inverted pyramid of * .
Algorithm :
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
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
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
Output
Learning Outcomes
VANSHIKA
EXPERIMENT 12
Problem statement:
Programming Code:
#include<stdio.h>
struct student {
char name[20];
int rollno;
float marks;
};
int main(){
int i,n;
scanf("%d",&n);
scanf("%d", &stuArr[i].rollno);
scanf("%f",&stuArr[i].marks);
printf("\nName:RollNo:Marks:\n");
return 0; }
VANSHIKA
Output
Learning Outcomes
VANSHIKA
SECTION 2
GGSIPU
VANSHIKA
EXPERIMENT 1
Problem statement:
Algorithm :
Pseudocode:
Output
VANSHIKA
Programming Code:
Output:
Learning Outcomes
VANSHIKA
EXPERIMENT 2
Problem statement:
Write a program to find sum of geometric series.
Algorithm :
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;
}
return 1;
else
fab=fabonacci(a-1)+fabonacci(a-2);
}
Output
Learning Outcomes
VANSHIKA
EXPERIMENT 4
Problem statement:
Addition of 2 Matrices
Subtraction of 2 Matrices
Finding upper and lower triangular Matrices
Transpose of a Matrix
Product of 2 Matrices
Algorithm :
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("\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("%d\t",mul[i][j]);
}
printf("\n");
}
break;
case 3:
}
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:
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("\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("\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
EXPERIMENT 5
Problem statement:
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++;
break ;
}
return 0;
}
Output
Length
VANSHIKA
Concatenation
Copy string
Reverse string
Learning Outcomes
VANSHIKA
EXPERIMENT 6
Problem statement:
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:
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:
Programming Code:
VANSHIKA
Output
ORIGINAL FILE