C Practical Arjav

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 67

Page |1

Object No 1:-Write a program in which you declare variable of all data type
supported by ‘c’ language. Get input from user and print the value of each
various with alignment left. Right and column width 10. For real number print
their values with two digit right to the decimal.

Source Code:

/* Name of programmer : Arjav jain Date: 21/10/22


Path :C:\TURBOC3\BIN\Arjav \Unit no:*/
#include<stdio.h>
#include<conio.h>
void main()
{
char c;
int i;
float f;
double d;
clrscr();
printf("Enter any character\n");
scanf("%c",&c);
printf("Enter any integer\n");
scanf("%d",&i);
printf("Enter any float value\n");
scanf("%f",&f);
printf("Enter any double value\n");
scanf("%f",&d);
printf("Left Align right Align\n");
printf("%10c\t%.10c\n",c,c);
printf("%10d\t%.10c\n",i,i);
printf("%10.2f\t%.10c\n",f,f);
printf("%10.2lf\t%.10lf\n",d,d);
getch();
}

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


Page |2

Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


Page |3

Object No 2:Write program to generate following pattern:


i)A ii) *
BC * * *
CDE * * * * *
EFGH

iii)1 iv) 1
12 11
123 121
1234 1331
14641
SOURCE CODE
(i)
/*Name of programmer : Arjav jain Date:- 11/10/22
Path:- C:\TurboC++\Disk\TurboC3\BIN\Que2.c Unit no :- */
//A program of pattern
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
clrscr();
for(i=1;i<=4;i++)
{
k = i;
for(j=1;j<=i;j++,k++)
{
printf("%c",(char)(k+64));
}
printf("\n");
}
getch();
}

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


Page |4

Input and Output:

(ii)
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j,k;
clrscr();
for (i=1; i<=3;i++)
{
for (j=1;j<=3-i;j++)
{
printf (" ");
}
for (k=1;k<=(2*i-1);k++)
{
printf ("* ");
}
printf ("\n");
}
getch();
}
Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


Page |5

(iii)
#include<stdio.h>
#include<conio.h>
void main()
{
int r,c;
clrscr();
for(r=1;r<=4;r++)
{
for(c=1;c<=r;c++)
{
printf("%d ",c);
}
//for(c=1;c<=3-r;c++)
printf("\n");
}
getch();
}
Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


Page |6

(iv)
#include<stdio.h>
#include<conio.h>
void main()
{
int i, res=1;
clrscr();
for(i=1; i<=5; i++)
{
if(i == 1)
res = i;
else
res = res * 11;
printf("%d", res);
printf("\n");
}
getch();
}
Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


Page |7

Object No 3:-Write program to display number 1 to 10 in octal, decimal and


hexadecimal system

Source Code:

/*Name of programmer: Arjav jain Date:- 15/10/22


Path of program: C:\TurboC3\BIN\AB\DEC_AB.C Unit no:/*
//A program of number 1 to 10 in octal, decimal and hexadecimal
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
printf("--------------------------------------\n");
printf("Decimal | Octal | Hexadecimal");
printf("\n------------------------------------");
while(i<=10)
{
printf("\n %d\t | %o\t | %x ",i,i,i);
i++;
}
getch();
}
Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


Page |8

Object No 4:-Write a program to perform following tasks using switch…case,


loops and conditional operator(as and when necessary)
a) Find factorial of a number
b) Print Fibonacci series up to n terms and its sum
c) Print prime numbers up to n terms
d) Print Whether a given year is leap or not not

Source Code:

/*Name of programmer: Arjav jain Date:- 22/10/22


Path of program: C:\TurboC3\BIN\AB\DEC_AB.C Unit no:/*
// A program of menu based programs switch case, loops and conditional
operator.
#include<stdio.h>
#include<conio.h>
void main()
{
int choice,fact=1,a,b,c,i,n,num=2,year,sum=2,count=0,leap;
clrscr();
printf("1.Find Factorial Number\n"
"2.Print Fibonacci series up to n terms and Its sum\n"
"3.Print Prime numbers up n terms\n"
"4.Print whether a given year is leap or not\n"
"Enter Your Choice:-");
scanf("%d",&choice);
switch(choice)
{
case 1printf("Enter The value to find factorial:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("Factorial of %d is %d",n,fact);
break;

case 2:printf("Enter N terms for fibonacci series:");

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


Page |9

scanf("%d",&n);
a=1;
b=1;
printf("%d %d ",a,b);
for(i=3;i<=n;i++)
{
c=a+b;
sum=sum+2;
printf("%d",c);
a=b;
b=c;
}
printf("\nTotal is %d",sum);
break;
case 3: i=1;
printf("Enter Any Number:");
scanf("%d",&num);
while(i<=2)
{
if(num%i==0)
{
count++;
}
i++;
}
if(count==2)
{
printf("It is a prime number");
}
else
{
printf("It is not a prime number");
}
break;
case 4: printf("Enter Any Year:");
scanf("%d",&year);
leap=year%4;

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 10

if(leap==0)
{
printf("It is leap year");
}
else
{
printf("It is not a leap year");
}
break;
default:printf("\nYou Have To Enter Valid choice");
}
getch();
}
Input and Output

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 11

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 12

Object No 5:-Write a program to reverse the string without using library


functions.

Source Code:

/*Name of programmer: Arjav jain Date: 21/10/22


Path of program: C:\TurboC++\Disk\TurboC3\BIN\Que7.C Unit no:/*
//A program to reverse the string without using library functions
#include<stdio.h>
#include<string.h>
void main() {
char str[100], temp;
int i, j = 0;
clrscr();
printf("Enter the string :");
gets(str);
i = 0;
j = strlen(str) - 1;
while (i < j) {
temp = str[i];
str[i] = str[j];
str[j] = temp;
i++;
j--;
}
printf("\nReverse string is :%s", str);
getch();
}
Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 13

Object No:-6 Write a program to count the number of character in string


without using library functions
Source Code:

/*Name of programmer: Arjav jain Date:- 25/10/22


Path of program: C:\TurboC++\Disk\TurboC3\BIN\Que7.C Unit no:/*
//A program to count the number of character in string.
#include<stdio.h>
#include<conio.h>
void main()
{
char str1[50];
int i, l = 0;
clrscr();

printf("\n\nFind the length of a string \n ");


printf("Input a string : ");
scanf("%s", str1);

for (i = 0; str1[i] != '\0'; i++)


{
l++;
}
printf("The string contains %d number of characters. \n",l);
printf("So, the length of the string %s is : %d\n\n", str1, l);

getch();
}
Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 14

Object No 7:-Write a program to copy the one string to other string without
using library function

Source Code:

/*Name of programmer: Arjav jain Date:- 30/10.22


Path of program: C:\TurboC++\Disk\TurboC3\BIN\Que7.C Unit no:/*
//A program to copy the one string to another string
#include <stdio.h>
#include<conio.h>
void main() {
char s1[100], s2[100], i;
clrscr();
printf("Enter string s1: ");
fgets(s1, sizeof(s1), stdin);
for (i = 0; s1[i] != '\0'; ++i) {
s2[i] = s1[i];
}
s2[i] = '\0';
printf("String s2: %s", s2);
getch();
}
Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 15

Object No 8:-Write a program find whether a given string is palindrome or not


without using library functions.

Source Code:

/*Name of programmer: Arjav jain Date:-05/09/2022


Path of program: C:\TurboC++\Disk\TurboC3\BIN\Que7.C Unit no:3 /*
//A program to find whether a given string is palindrome or not.
#include<stdio.h>
#include<conio.h>
void main()
{
char string[40];
int length=0, flag=1,i;
clrscr();
printf("Enter string:\n");
gets(string);
for(i=0;string[i]!='\0';i++)
{
length++;
}
for(i=0;i< length/2;i++)
{
if( string[i] != string[length-1-i] )
{
flag=0;
break;
}
}
if(flag==1)
{
printf("PALINDROME");
}
else
{
printf("NOT PALINDROME");
}

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 16

getch();
}
Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 17

Object No 9:-Write a program that read the afternoon day temperature for
each day of the month and then report the month average temperature.
Source Code:

/*Name of Programmer : Arjav Verma Date :6/9/22


Path of program :C:\Turbo3\Bin\Arjav \temp3.c Unit no. :*/
//A program to read the afternoon day and generate report.
#include<stdio.h>
#include<conio.h>
void main()
{
float temparray[31],sum=0,average;
int i;
clrscr();
for(i=0;i<30;i++)
{
printf(“enter the temperature reading of the day:%d=”,i+1);
scanf(“%f”,&temparray[i]);
sum=sum+temparray[i];
}
average=sum/30.0;
printf(“the average temperature of the month is=%.2f”,average);
getch();
}
Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 18

Object No 10:-Create a single program to perform following tasks using switch,


if..else , loop and double dimension integer array of size 3*3:
a)Addition of two matrix.
Multiplication of two matrix.
Transpose of matrix.
Source code:

/*Name of programmer : Arjav jain Date:13/10/2022


Path:C:\TurboC3\BIN\Arjav \Matrix.c Unit no:2 */
//A program of matrix
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],i,j,k,choice;
clrscr();
printf(“1 for Addition of two matrix”);
printf(“2 for Multiplication of two matrix”);
printf(“3 for Transpose of matix”);
printf(“Enter elements for first matrix:”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“Enter number in pocket for first matrix[%d][%d]”,i,j);
scanf(“%d”,&a[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“%d\t”,a[i][j]);
}
printf(“\n”);
}
printf(“Enter elements for second matrix:”);

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 19

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“Enter number in pocket for second matrix[%d][%d]”,i,j);
scanf(“%d”,&b[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“%d\t”,b[i][j]);
}
printf(“\n”);
}
printf(“Enter your choice:”);
scanf(“%d”,&choice);
switch(choice)
{
case 1:
{
printf(“Addition of two matrix:”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf(“%d\t”,c[i][j]);
}
printf(“\n”);
}
}
break;
case 2:
{
printf(“Multiplication of two matrix:”);

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 20

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=0;
for(k=0;k<3;k++)
{
c[i][j]=c[i][j]+a[i][j]*b[i][j];
}
printf(“%d\t”,c[i][j]);
}
printf(“\n”);
}
}
break;
case 3:
{
printf(“Transpose of matrix is:”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“%d\t”,a[j][i]);
}
printf(“\n”);
}
}
getch();
}

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 21

Input and Output

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 22

Object No 11:-Write a program to find an element in a linear array.

Source Code:

/*Name of programmer: Arjav jain Date:-


Path of program: C:\TurboC3\BIN\Farhat\ARR_SEAR.C Unit no: */
// A program to find an element in a linear array
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[15],size,i,s_e,count=0;
clrscr();
printf("Enter array size max is 15 : ");
scanf("%d",&size);
printf("Enter array elements : ");
for(i=0;i<size;i++)
{
scanf("%d",&arr[i]);
}
printf("Enter element which u want to search : ");
scanf("%d",&s_e);
for(i=0;i<size;i++)
{
if(arr[i]==s_e)
{
count++;
break;
}
}
if(count==0)
printf("Search not found");
else
printf("Element found");
getch();
}

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 23

Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 24

Object No 12:-Write a program to find greatest & smallest element in a linear


array.

Source Code:

/*Name of programmer: Arjav jain Date:- 6/9/22


Path of program: C:\TurboC3\BIN\AB\GRET_LOW.C Unit no: */
//A program of greatest and smallest element array
#include<stdio.h>
#include<conio.h>
void main()
{
int size,max,min,i,list[25];
clrscr();
printf("Enter list size max is 25:-");
scanf("%d",&size);
printf("Enter list Element:\n");
for(i=0;i<size;i++)
{
printf("%d",i);
scanf("%d",&list[i]);
}
max=list[0];
for(i=0;i<size;i++)
{
if(max<list[i])
{
max=list[i];
}
}
min=list[0];
for(i=0;i<size;i++)
{
if(min>list[i])
{
min=list[i];

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 25

}
}
printf("List of elements are:-\n");
for(i=0;i<size;i++)
{
printf("Elements %d:%d \n",i,list[i]);
}
printf("Max Element in the list is: %d\n",max);
printf("Min Element in the list is: %d",min);
getch();
}
Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 26

Object No 13 :-Write a program of sorting of element in an array

Source Code:

/*Name of programmer: Arjav jain Date:- 7/10/22


Path of program: C:\TurboC3\BIN\Arjav \ARR_SORT.C Unit no: */
// A program to find an element in a linear array
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[15],size,i,j,temp;
clrscr();
printf("Enter array size max is 15 : ");
scanf("%d",&size);
printf("Enter array elements : ");
for(i=0;i<size;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<size-1;i++)
{
for(j=0;j<size-i-1;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
printf("After sorting array elements : ");
for(i=0;i<size;i++)
{
printf("\n%d",arr[i]);

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 27

}
getch();
}
Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 28

Object No 14:-Write program using the function power(a,b) to calculate the


value of a raised b.

Source Code:

/*Name of programmer: Arjav jain Date:- 10/11/22


Path of program: C:\TurboC3\BIN\AB\POW_AB.C Unit no: */
//A program of power using function
#include<stdio.h>
#include<conio.h>
void pow(int a,int b);
void main()
{
int a,b;
clrscr();
printf("Enter Value of A:");
scanf("%d",&a);
printf("Enter Value of B:");
scanf("%d",&b);
pow(a,b);
getch();
}
void pow(int a,int b)
{
int result=1,i;
for(i=1;i<=b;i++)
{
result=result*a;
}
printf("Power is %d",result);
}
Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 29

Object No 15:-Write a program to demonstrate difference between static and


auto variable.

Source Code:

/*Name of programmer: Arjav jain Date:- 9/12/22


Path of program: C:\TurboC3\BIN\AB\AUTSTA_AB.C Unit no:*/
// A program to demonstrate difference between static and auto variable
#include<stdio.h>
#include<conio.h>
int exa_static();
void main()
{
int i;
clrscr();
for(i=0;i<5;i++)
{
exa_static();
}
getch();
}
int exa_static()
{
auto int a=0;
static int b;
printf("Auto Variable is a=%d , Static Variable is b=%d\n",a,b);
a++;
b++;
}
Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 30

Object No 16:-Write a program to demonstrate difference between local and


global variable

Source Code:

/*Name of programmer: Arjav jain Date:- 3/12/22


Path of program: C:\TurboC3\BIN\AB\GLO_AB.C Unit no:*/
//A program of local and global variable
#include<stdio.h>
#include<conio.h>
int g_v;
void display();
void main()
{
clrscr();
printf("first function call");
display();
printf("\nSecond Function Call");
display();
printf("\nThird Function Call");
display();
getch();
}
void display()
{
int l_v=3;
printf("\n global variable %d",g_v);
printf("\n local variable %d",l_v);
g_v++;
l_v++;
}

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 31

Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 32

Object No 17:- Write a program to find factorial of a number

Source Code:

/*Name of programmer: Arjav jain Date:- 5/9/22


Path of program: C:\TurboC3\BIN\Arjav \Fact.C Unit no:*/
//A program of factorial using second category of functions.
#include<stdio.h>
#include<conio.h>
void facto(int);
void main()
{
int n;
clrscr();
printf("Enter any number:");
scanf("%d",&n);
facto(n);
getch();
}
void facto(int n)
{
int i,fact=1;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("Factorial of %d is %d",n,fact);
}
Input and Output

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 33

Object No 18:- Write a program to print Fibonacci series up to n terms and its
sum

Source Code:

/*Name of programmer: Arjav verma Date:- 6/10/22


Path of program: C:\TurboC3\BIN\Kum\Fib.C Unit no:*/
//A program to print Fibonacci series and its n terms
#include<stdio.h>
#include<conio.h>
void fibo(int);
void main()
{
int n;
clrscr();
printf("Enter N terms of fibonacci series:");
scanf("%d",&n);
fibo(n);
getch();
}
void fibo(int n)
{
int a,b,c,i,sum=2;
a=1;
b=1;
printf("%d %d ",a,b);
for(i=3;i<=n;i++)
{
c=a+b;
sum=sum+c;
printf("%d",c);
a=b;
b=c;
}
printf("\nTotal is:%d",sum);
}

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 34

Input and Output

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 35

Object No 19:-Create a program to perform following task using switch….case,


loops and recursive functions.
a) Find factorial of a number.
b) Print Fibonacci series up to n terms and its sum.

Source Code:

/*Name of Programmer: Arjav jain Date: 8/12/22


Path of Program :C:\Turboc3\Bin\Arjav \recursive.c Unit no : */
//A program to find factorial of a number and print Fibonacci series upto n
terms and its sum using switch…case, loops and recursive functions.
#include <stdio.h>
#include <conio.h>
int factorial(int n);
void main()
{
int opt, num1, num2, n1, n2, n3, term, i, choice;
char ch;
clrscr();
printf("1. factorial of a number(recur).\n");
printf("2. fionacci series and its sum.\n");
do
{
printf("Choose your option:");
scanf("%d", &opt);
switch (opt)
{
case 1:
printf("Enter the Number:");
scanf("%d", &num1);
printf("Factorial of %d is %d", num1, factorial(num1));
break;
case 2:
printf("Enter the term:");
scanf("%d", &term);
n1 = 0;
n2 = 1;
printf("fibonacci series is as shown:%d %d ", n1, n2);
for (i = 2; i < term; i++)

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 36

{
n3 = n1 + n2;
printf("%d ", n3);
n1 = n2;
n2 = n3;
}
break;
default:
printf("invalid option please choose valid option.");
}
printf("\nyou want to do again (Enter: y/n):");
scanf("%d", &dummy);
scanf("%c", &ch);
} while (ch == 'Y' || ch == 'y');
getch();
}
int factorial(int n)
{
if (n >= 1)
return n * factorial(n - 1);
else
return 1;
}
Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 37

Object No 20:-Write a function to accept 10 characters and display whether


each input character is digit, uppercase letter or lowercase letter.

Source Code:

/*Name of Programmer: Arjav jain Date: 4/11/22


Path of Program: C:\Turboc3\Bin\BCA1B\QUE15.c Unit no:*/
// A program to find an element in a linear array
#include<stdio.h>
#include<conio.h>
void check();
void main()
{
clrscr();
check();
getch();
}
void check()
{
char str[50],i;
printf("Enter any string : ");
gets(str);
for(i=0;str[i]!=NULL;i++)
{
if(str[i]>=65 && str[i]<=90)
{
printf("%c : Upper Case\n",str[i]);
}
else if(str[i]>=97 && str[i]<=122)
{
printf("%c : Lower Case\n",str[i]);
}
else if(str[i]>=48 && str[i]<=57)
{
printf("%c : Digit\n",str[i]);
}
else
{
printf("%c : Other\n",str[i]);
}

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 38

}
}
Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 39

Object No 21:-Create a single program to perform to following tasks using


switch, if...else, loop,
function and double dimensional integer array of size 3x3.
a.) Addition of two matrix.
b.) Multiplication of two matrix

Source Code:

/* Name of Programmer : Arjav jain Date: 4/12/22


Path of Program:C:\TurboC++\Disk\TurboC3\BIN\S\ADD.CUnit: */
#include <stdio.h>
void main()
{
int a[3][3], b[3][3], c[3][3], i, j;
int choice;
printf("Enter First Matrix Elements \n ");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
printf("Enter First Number in Pocket [%d] [%d]", i, j);
scanf(" %d",&a[i][j]);
}
}
printf("\n Enter Second Matrix Number \n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
printf("Enter Second Number in Pocket [%d] [%d]", i, j);
scanf(" %d",&b[i][j]);
}
}
printf("\n First Matrix...\n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 40

{
printf(" %d",a[i][j]);
}
printf("\n");
}
printf("\n Second Matrix...\n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
printf(" %d",b[i][j]);
}
printf("\n");
}
printf("Enter your choice : ");
scanf(" %d",&choice);
if(choice==1)
{
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("\n Addition of two Matrix...\n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
printf(" %d ",c[i][j]);
}
printf("\n");
}
}
else if(choice==2)
{

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 41

for(i=0; i<3; i++)


{
for(j=0; j<3; j++)
{
c[i][j]=a[i][j]*b[i][j];
}
}
printf("\n Multiplication of two Matrix...\n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
printf(" %d ",c[i][j]);
}
printf("\n");
}
}
else
{
printf("You have made wrong choice");
}

getch();
}

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 42

Input and Output:-

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 43

Object No 22:-Create a single program to perform following tasks using switch


case, if else , loop, user defined functions and single dimension character array:
a) To reverse the string
b) To find whether a given string is palindrome or not

Source Code:

/*Name of programmer: Arjav jain Date:- 6/12/22


Path of program: C:\TurboC3\BIN\Arjav \REV_PAL.C Unit no:*/
//A program to reverse the string
#include<stdio.h>
#include<conio.h>
void reverse(char[]);
void palindrome(char[]);
void main()
{
char choice, string[10];
clrscr();
printf("Enter any string : ");
gets(string);
printf("\nPress\n");
printf("a : Reverse of string\n");
printf("b : To check string palindrome\n");
printf("\nEnter our choice : ");
scanf("%c",&choice);
if(choice=='a')
{
reverse(string);
}
else if(choice=='b')
{
palindrome(string);
}
else
printf("Wrong Entry");
getch();
}

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 44

void reverse(char str[10])


{
int i,len=0;
for(i=0;str[i]!=NULL;i++)
{
len++;
}
printf("\nReverse of String %s is : ",str);
for(i=len;i>=0;i--)
{
printf("%c",str[i]);
}
}
void palindrome(char str[10])
{
int i,j,c=0,len=0;
for(i=0;str[i]!=NULL;i++)
{
len++;
}
j=len;
for(i=0;i<len;i++,j--)
{
if(str[i]!=str[j-1])
{
c++;
break;
}
}
if(c==0)
printf("String is Palindrome");
else
printf("String is not palindrome");
}

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 45

Input and Output

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 46

Object No 23:- Create a structure student having data members to store roll
no.,name max mark,min mark, obtained marks.Declare a structure variable of
student provided facility to input in data members and display result of
student.

Source Code:

/* Name of programmer : Arjav jain Date: 3/12/22


Path :C:\TURBOC3\BIN\Arjav \Struct_EMP.C Unit no:*/
//A program to create structure of student.
#include<stdio.h>
#include<conio.h>
struct student
{
int r_n;
char s_name[20];
char subName[3][10];
int min,max,obj;
};
void main()
{
int i;
struct student s1;
clrscr();
printf("Enter student Name : ");
gets(s1.s_name);
printf("Enter Roll no Name : ");
scanf("%d",&s1.r_n);
printf("Enter Roll no Name : ");
scanf("%d",&s1.r_n);
scanf("%d",&s1.r_n);
for(i=0;i<3;i++)
{
printf("\nEnter name of subject %d : ",i+1);
scanf("%s",&s1.subName[i]);
}
printf("Enter minimum mark : ");
scanf("%d",s1.min);
printf("Enter maximum mark : ");
scanf("%d",s1.max);

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 47

printf("Enter obtained mark : ");


scanf("%d",s1.obj);
clrscr();
printf("\n------STUDENT DETAILS------\n");
printf("Roll No : %d\n",s1.r_n);
printf("Student Name : %s\n",s1.s_name);
for(i=0;i<3;i++)
{
printf("Subject %d : %s\n",i+1,s1.subName[i]);
}
printf("Minimum marks : %d\n",s1.min);
printf("Maxmum marks : %d\n",s1.max);
printf("Obtained marks : %d",s1.obj);
getch();
}
Input and Output

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 48

Object No24 :-Create a structure date with data member’s dd, mm, yy (to
store date).Create another structure employee with data members to hold
name of employee, employee id and date of joining (date of joining will be
hold by variable of structure date which appears as data members in Employee
Structure).Store data of an employee and print the same.

Source Code:

/*Name of programmer: Arjav jain Date:- 12/11/22


Path of program: C:\TurboC3\BIN\Arjav \EMP_STRUCT.C Unit no: */
//A program to create structure of employee
#include<stdio.h>
#include<conio.h>
struct Employee
{
char ename[20];
int eid;
struct Date
{
int dd;
int Month;
int Year;
}d;
}e;
void main()
{
struct Employee e;
struct Date d;
clrscr();
printf("Enter name of employee:");
gets(e.ename);
printf("Enter Employee Id:");
scanf("%d",&e.eid);
printf("Enter Date:");
scanf("%d",&e.d.dd);
printf("Enter Month:");
scanf("%d",&e.d.Month);

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 49

printf("Enter Year:");
scanf("%d",&e.d.Year);
printf("\nEmployee Details\n");
printf("Name of Employee:%s\n",e.ename);
printf("Employee Id:%d\n",e.eid);
printf("Date of joining:%d/%d/%d",e.d.dd,e.d.Month,e.d.Year);
getch();
}
Input and Output

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 50

Object No 25:-Create a Structure student having data member to store roll no,
number of student ,name of the three subject ,max marks,min marks, obtained
marks. Declare array of structure to hold data of 3 student . Provide Facilities
to display result of all student .

Source code:-

/*Name of programmer :- Arjav jain Date:- 12/12/22


Path:-C:\TURBOC3\BIN\PRASOON Unit:-*/
//A program of structure student
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct student
{
char name[30];
int roll;
int max;
int min;
int math;
int science;
int hindi;
};
void main()
{
struct student s[2];
clrscr();
strcpy(s[0].name,"PRASOON ");
s[0].roll=12;
s[0].max=100;
s[0].min=33;
s[0].math=98;
s[0].science=89;
s[0].hindi=80;
printf("NAME :- %s\nROLL NO:- %d\nSUBJECT\t MAX\t MIN\t OBT\nMATH\t
%d\t %d\t %d\nSCIENCE\t %d\t %d\t %d\nHINDI\t %d\t %d\t %d\n\

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 51

n",s[0].name,s[0].roll,s[0].max,s[0].min,s[0].math,s[0].max,s[0].min,s[0].scie
nce,s[0].max,s[0].min,s[0].hindi);
strcpy(s[1].name,"KUNDAN");
s[1].roll=13;
s[1].max=100;
s[1].min=33;
s[1].math=100;
s[1].science=92;
s[1].hindi=85;
printf("NAME :- %s\nROLL NO:- %d\nSUBJECT\t MAX\t MIN\t OBT\nMATH\t
%d\t %d\t %d\nSCIENCE\t %d\t %d\t %d\nHINDI\t %d\t %d\t %d\n\
n",s[1].name,s[1].roll,s[1].max,s[1].min,s[1].math,s[1].max,s[1].min,s[1].scie
nce,s[1].max,s[1].min,s[1].hindi);
strcpy(s[2].name,"RAVI");
s[2].roll=14;
s[2].max=100;
s[2].min=33;
s[2].math=70;
s[2].science=70;
s[2].hindi=55;
printf("NAME :- %s\nROLL NO:- %d\nSUBJECT\t MAX\t MIN\t OBT\nMATH\t
%d\t %d\t %d\nSCIENCE\t %d\t %d\t %d\nHINDI\t %d\t %d\t %d\n\
n",s[2].name,s[2].roll,s[2].max,s[2].min,s[2].math,s[2].max,s[2].min,s[2].scie
nce,s[2].max,s[2].min,s[2].hindi);
getch();
}
Input and Output

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 52

Object No 26:-Write A program of swapping two numbers and demonstrates


call by value and call by reference

Source code:-

/*Name of programmer :- Arjav jain Date:- 3/12/22


Path:-C:\TURBOC3\BIN\Arjav \SWAP_VALUE.C Unit:- */
//A program of swapping two numbers and demonstrates call by value and
call by reference.
#include<stdio.h>
#include<conio.h>
void swap(int,int);
void main()
{
int a,b;
clrscr();
printf("Enter value A:");
scanf("%d",&a);
printf("Enter Value B:");
scanf("%d",&b);
printf("Before swapping the values a=%d,b=%d\n",a,b);
swap(a,b);
getch();
}
void swap(int a,int b)
{
int c;

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 53

c=a;
a=b;
b=c;
printf("After swapping the values in function a=%d,b=%d",a,b);
}
Input and output

//A program of call by reference.


#include<stdio.h>
#include<conio.h>
void swap(int*,int*);
void main()
{
int a,b;
clrscr();
printf("Enter Value A:");
scanf("%d",&a);
printf("Enter Value B:");
scanf("%d",&b);
printf("Before swapping the values a=%d,b=%d\n",a,b);
swap(&a,&b);
getch();
}
void swap(int*a,int*b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
printf("After Swapping values in functions a=%d,b=%d\n",*a,*b);
}
Input and Output

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 54

Object No 27:- Write a program to find biggest number among three numbers
using pointer and function.

Source Code:

/*Name of programmer: Arjav jain Date:- 7/12/22


Path of program: C:\TurboC3\BIN\Arjav \F_Greater.C Unit no:*/
//A program to find biggest number among three numbers
#include<stdio.h>
#include<conio.h>
void greater(int*,int*,int*);
void main()
{
int a,b,c;
clrscr();
printf("Enter any 3 nos : ");
scanf("%d%d%d",&a,&b,&c);
greater(&a,&b,&c);
getch();
}
void greater(int *a,int *b,int *c)
{
if(*a > *b && *a > *c)
printf("%d is greater",*a);
else if( *b > *c)
printf("%d is greater",*b);
else
printf("%d is greater",*c);
}
Input and Output

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 55

Object No 28:-Write program to create a structure Employee having data


member to store name of employee, employee id,salary.Use pointer to
structure to store data of employee and print the stored data-using pointer to
structure.

Source code:-

/*
Name of Programmer :- Arjav jain Date :-8/11/22
Path:-C:\TURBOC3\BIN\KUNDAN Unit:- */
//A program to create structure employee with salary
#include<stdio.h>
#include<conio.h>
struct employee
{
char name[30];
int id;
float salary;
};
void main()
{
struct employee emp={"Kundan",45,35000};
struct employee *ptr;
ptr=&emp;
clrscr();
printf("Employee Information :\n");
printf("Name : %s\n",ptr->name);
printf("ID : %d\n",ptr->id);
printf("Salary : %f\n",ptr->salary);
getch();

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 56

}
Input & Output:-

Object No 29:-Write a program to demonstrate difference between character


array and pointer to character.

Source Code:

/*Name of programmer: Arjav jain Date:-13-09-2022


Path of program: C:\TurboC3\BIN\Arjav \CHAR_AB.C Unit no:25 */
//A program to demontarte chracter array and pointer to character
#include<stdio.h>
#include<conio.h>
void main()
{
char *name[3]={"Anuj","Raj","Manya"};
int i;
clrscr();
printf("Names Given By user:\n");
for(i=0;i<3;i++)
{
printf("%s\n",name[i]);
}
getch();
}
Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 57

Object No 30:-Write a program to demonstrate pointer arithmetic

Source Code:

/*Name of programmer: Arjav jain Date:- 10/10/22


Path of program: C:\TurboC3\BIN\AB\ARITH_AB.C Unit no:*/
//A program to demonstrate pointer arithmetic
#include<stdio.h>
#include<conio.h>
void arith(int*,int*);
void main()
{
int a,b;
clrscr();
printf("Enter Value of A:");
scanf("%d",&a);
printf("Enter Value of B:");
scanf("%d",&b);
arith(&a,&b);
getch();
}
void arith(int*a1,int*b1)
{

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 58

int sum,multi,divi,sub;
sum=*a1+*b1;
printf("Addition is:%d",sum);
multi=*a1**b1;
printf("\nMultilication is:%d",multi);
divi=(*a1)/(*b1);
printf("\nDivision is:%d",divi);
sub=*b1-*a1;
printf("\nSubtraction is:%d",sub);
}

Input and Output:

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 59

Object No 31:- Write a program to demonstrate use of file inclusion of pre-


processor directive.

Source Code:

/*Name of programmer: Arjav jain Date:- 5/12/22


Path of program: C:\TurboC3\BIN\AB\ARITH_AB.C Unit no: */
//A program of file inclusion
#define C 10
#define D 20
//A program of file inclusion
#include<stdio.h>
#include<conio.h>
#include"F_INCLUD.C"
void main()
{
clrscr();
printf("Addition of %d and %d is %d",C,D,C+D);
getch();
}
Input and Output

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 60

Object No 32:-Write a program to copy content of one file to other file

Source Code:

/*Name of programmer: Arjav jain Date:- 7/12/22


Path of program: C:\TurboC3\BIN\AB\COPY_AB.C Unit no:*/
//A program to copy file content to another file
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
FILE *fp1,*fp2;
char c;
clrscr();
fp1=fopen("AB.txt","r");
if(fp1==NULL)
{
printf("The file does not exist");
exit(1);
}

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 61

//fp2=fopen("Data.txt","w");
if(fp2==NULL)
{
printf("The data does not exist");
exit(1);
}
while((c=fgetc(fp1))!=EOF)
{
fputc(c,fp2);
}
printf("AB.txt->Data.txt\n");
printf("Successfully copied the content\n");
printf("Ab.txt contents are:-\n");
fp1=fopen("AB.txt","r");
c=fgetc(fp1);
while(c!=EOF)
{
printf("%c",c);
c=fgetc(fp1);
}
printf("\nData.txt contents are:-\n");
fp2=fopen("Data.txt","r");
c=fgetc(fp2);
while(c!=EOF)
{
printf("%c",c);
c=fgetc(fp2);
}
fclose(fp1);
fclose(fp2);
getch();
}
Input and Output

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 62

Object No 33:- Write a program to create a file “data” containing a series of


integers and count all even and odd numbers present in the file “data”.

Source Code:

/*Name of programmer: Arjav jain Date:-06-09-2022


Path of program: C:\TurboC3\BIN\Farhat\EVE_DATA.C Unit no: */
//A program to count even and odd numbers in a file.
#include<stdio.h>
#include<conio.h>
void main()
{
int num;
FILE *fp,*e,*o;
clrscr();
//creating & opening file for writing
fp=fopen("input1.txt","w");
e=fopen("even.txt","w");

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 63

o=fopen("odd.txt","w");
printf("Press -1 to break : \n");
while(1)
{
scanf("%d",&num);
if(num==-1)
break;
else
{
putw(num,fp);
if(num%2==0)
{
putw(num,e);
}
else
{
putw(num,o);
}
}
}
fclose(fp);
fclose(e);
fclose(o);
//opening file for reading
printf("\n\nInput1 File Data is \n");
fp=fopen("input1.txt","r");
while((num=getw(fp))!=EOF)
{
// putw(num,stdout);
printf(" %d",num);
}
fclose(fp);

printf("\n\nEven File Data is \n");


fp=fopen("even.txt","r");
while((num=getw(fp))!=EOF)
{
// putw(num,stdout);
printf(" %d",num);
}

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 64

fclose(e);

printf("\n\nOdd File Data is \n");


fp=fopen("odd.txt","r");
while((num=getw(fp))!=EOF)
{
// putw(num,stdout);
printf(" %d",num);
}
fclose(o);
getch();
}
Input and Output

Object No 34:- Write a program to count no of vowels & consonants of a file

Source Code:

/*Name of programmer: Arjav jain Date:-06-09-2022


Path of program: C:\TurboC3\BIN\Arjav \VOW_CONS.C Unit no:*/
// A program to count vowel and consonants of a file.
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
int v=0,c=0,s=0;
FILE *fp;
clrscr();
fp = fopen("input.txt","w");
printf("Enter only charater data : \n\n");

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 65

while((ch=getc(stdin))!=EOF)
{
putc(ch,fp);
}
fclose(fp);
printf("File content is \n\n");
fp=fopen("input.txt","r");
while((ch=getc(fp))!=EOF)
{
putc(ch,stdout);
if(ch=='a'||ch=='i'||ch=='o'||ch=='e'||ch=='u'||ch=='A'||ch== 'I'||
ch=='O'||ch=='E'||ch=='U')
v++;
else if(ch==' ')
s++;
else
c++;
}
printf("\n\nNo. of vowel : %d\n",v);
printf("No. of consonent : %d\n",c);
printf("No. of space : %d",s);
fclose(fp);
getch();
}
Input and Output

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 66

Object No 35:- Write a program to create “Dummy.txt”& Perform Random


access file operation.

Source Code:

/*Name of programmer: Arjav jain Date:- 2/12/22


Path of program: C:\TurboC3\BIN\Arjav \RAF.C Unit no:*/
// A program to create “Dummy.txt” and perform operation.
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
FILE *fp;
clrscr();
printf("Enter Data Here \n");
fp=fopen("input.txt","w");
while((ch=getc(stdin))!=EOF)

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM


P a g e | 67

{
putc(ch,fp);
}
fclose(fp);
fp=fopen("input.txt","r");
printf("\n\nFile Content Moveing file pointer forword by 5th byte using
fseek() from beginning \n");
fseek(fp,5,0);
while((ch=getc(fp))!=EOF)
{
printf("\nCharacter at position %d : ",ftell(fp));
putc(ch,stdout);
}
rewind(fp);
printf("\n\nFile content After rewind function\n");
while((ch=getc(fp))!=EOF)
{
printf("\nCharacter at position d%d : ",ftell(fp));
putc(ch,stdout);
}
fclose(fp);
getch();
}
Input and Output

GDRCST BCA-1 2022-23PROGRAMMING IN C GUIDED BY: Ms. FARHAT ANJUM

You might also like