SNDT Women’s University
Mumbai ,
Maharishi Karve Mahila Sakshmeekaran
Gyansankul
Tah. Ballarpur Dist. Chandrapur
Bachelor of computer application
(BCA)
A practical record of C programming
submitted to
Asst. Prof. Sheetal R. Billore
Submitted by
Riya Tilokani
December 2023
Stud. Riya T 1
SNDT Women’s University
Mumbai,
Ballarpur Campus…
SUBJECT TITLE: C PROGRAMMING
SUBJECT CODE: 1201
Practical No. Practical Name Page No.
1 C program to implement all operators 2
(+,-,*, /, %)
2 C program to implement relational 3
operator
3 C program to implement logical 4
operator
4 C program to find largest among any 5
five numbers with minimum condition
5 C program to find given number is 6
even or odd by using goto statement
6 C check the year is leap or not program 7
to
7 C program to generate a menu driven 8
program using statement
8 C program to print multiplication table 9
9 C program to find sum of digit to 10
reverse the given number check
whether the number is palindrome or
not
10 C program for list of prime number 11
between 10 – 100 by using break
statement
11 C program to display the days of week 12
by using switch statement
12 C program to find transpose of a 13
matrix
13 C program of function length () which 14
count length
Stud. Riya T 2
14 C program to except the value and 15
display the address of value by using
pointer
15 C program to display the result of 16
student
16 C program to create store information 17
in text file
Stud. Riya T 3
Practical 1: WRITE A C PROGRAM TO IMPLEMENT ALL
OPERATORS (+,-,*, /, %).
CODE:
#include <stdio.h>
#include<conio.h>
void main()
{
int a = 9,b = 4, c;
clrscr();
c = a+b;
printf("a+b = %d \n",c);
c = a-b;
printf("a-b = %d \n",c);
c = a*b;
printf("a*b = %d \n",c);
c = a/b;
printf("a/b = %d \n",c);
c = a%b;
printf("Remainder when a divided by b = %d \n",c);
getch();
}
OUTPUT:-
Stud. Riya T 4
PRACTICAL 2: WRITE A C PROGRAM TO IMPLEMENT
RELATIONAL OPERATOR.
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int x = 12, y = 13;
clrscr();
printf("x = %d\n", x);
printf("y = %d\n\n", y);
// Is x is greater than y?
printf("x > y : %d\n", x > y);
// Is x is greater than or equal to y?
printf("x >= y : %d\n", x >= y);
// Is x is smaller than y?
printf("x < y : %d\n", x < y);
// Is x is smaller than or equal to y?
printf("x <= y : %d\n", x <= y);
// Is x is equal to y?
printf("x == y : %d\n", x == y);
// Is x is not equal to y?
printf("x != y : %d\n", x != y);
// Signal to operating system everything works fine
getch();;
}
Output:-
Stud. Riya T 5
Practical 3: Write a program to implement logical operator.
CODE:
#include <stdio.h>
#include<conio.h>
void main()
{
int x = 5;
int y = 2;
int z = 0;
clrscr();
if (x > y && x > z) {
printf("x is the largest number\n");
}
if (y < x || z < x) {
printf("x is not the smallest number\n");
}
if (!(x == y)) {
printf("x is not equal to y\n");
}
getch();
}
Output:-
Stud. Riya T 6
Practical 4: Write a program to find largest among any five numbers
with minimum condition.
CODE:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a,b,c,d,e;
int lar;
clrscr();
printf("Enter any 5 values\n");
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
lar=a;
if(b>lar)
lar=b;
if(c>lar)
lar=c;
if(d>lar)
lar=d;
if(e>lar)
lar=e;
printf("Largest element is %d",lar);
getch();
}
Output:-
Stud. Riya T 7
Practical 5: write a c program to find given number is even or odd by
using goto statement.
CODE:
#include<stdio.h>
#include<conio.h>
void main(void)
int num,rem;
clrscr();
printf("Enter a number:-");
scanf("%d",&num);
rem=num%2;
if(rem==0)
printf("Number %d is Even",num);
else
printf("Number %d is Odd",num);
getch();
Output:-
Stud. Riya T 8
Practical 6: write a c check the year is leap or not program to.
CODE:
#include<stdio.h>
#include<conio.h>
void main(void)
int year;
clrscr();
printf("\n\t Enter Year :-");
scanf("%d",&year);
if(year%4==0)
printf("%d is a leap year",year);
else
printf("%d is not a leap year",year);
getch();
Output:-
Stud. Riya T 9
Practical 7: write a c program to generate a menu driven program using
statement.
CODE:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(void)
{
int cho;
do
{
clrscr();
printf("\n\t\t M E N U \n\n");
printf("\t\t (1) add \n");
printf("\t\t (2) edit \n");
printf("\t\t (3) delete \n");
printf("\t\t (4) exit \n");
printf("\t enter choice(1-4):-");
scanf("%d",&cho);
switch(cho)
{
case 1 : printf("\n\n addition routine");
break;
case 2 : printf("\n\n edit routine");
break;
case 3 : printf("\n\n delete routine");
break;
case 4 : exit(0);
}
getch();
}
while(cho!=4);
}
Output:-
Stud. Riya T 10
Practical 8: write a c program to print multiplication table.
CODE:
#include<stdio.h>
#include<conio.h>
Void main(void)
{
int n,r,i;
clrscr();
printf("Enter a number:-");
scanf("%d",&n);
for(i=1; i<=10; ++i)
{
r=n*i;
printf("\n%3d*%3d=%5d”,n,i,r);
}
getch();
}
Output:-
Stud. Riya T 11
Practical 9: write a c program to find sum of digit to recerse the given
number check weather the number is palindrome or not.
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int num,sum=0,orinum,rem,rev=0;
clrscr();
printf("\n Enter the number:- ");
scanf("%d",&num);
orinum=num;
while(num>0)
{
rem=num % 10;
rev=rev*10+rem;
sum=sum+rem;
num=num/10;
}
printf("\n\n Reverse of %d is %d",orium,rev);
printf("\n\n Sum of Digit %d ",sum);
if(orinum==rev)
printf("Number %d is palindrome",orinum);
else
printf("number %d is not palindrome",orinum);
getch();
}
Output:-
Stud. Riya T 12
Practical 10: write a c program for list of prime number between 10 –
100 by using break statement.
CODE:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int i,n,r,flag=0;
clrscr();
printf("\n\n\t\t List of Prime Numbers \n");
for(n=10; n<=100; ++n)
{
flag=0;
for(i=2; i<=9; ++i)
{
r=n%i;
if(r==0)
{
flag=1;
break;
}
}
if(flag==0)
{
printf("%d\t",n);
}
}
getch();
}
Output:-
Stud. Riya T 13
Practical 11: write a c program to display the days of week by using
switch statement.
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int day=1;
clrscr();
printf("The day with number %d is ",day);
switch(day)
{
case 1:
printf("sunday");
break;
case 2:
printf("monday");
break;
case 3:
printf("tuesday");
break;
case 4:
printf("wednesday");
break;
case 5:
printf("thursday");
break;
case 6:
printf("friday");
break;
case 7:
printf("saturday");
break;
default:
printf("invalid week days");
}
getch();
}
Output:-
Stud. Riya T 14
Practical 12: write a c program to find transpose of a matrix.
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int m,n,i,j,a[10][10];
clrscr();
printf("\n Enter the dimensions of matrix ");
scanf("%d %d",&m,&n);
printf("\n Enter the elements of matrix\n ");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("\n\t Original matrix is \n\t ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d ",a[i][j]);
printf("\n\t ");
}
printf("\n\t Transpose of matrix is \n\t ");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
printf("%d ",a[j][i]);
printf("\n\t ");
getch();
}
}
Output:-
Stud. Riya T 15
Practical 13: Write a c program of function length () which count
length.
CODE:
#include<stdio.h>
#include<conio.h>
int lenght(char*s)
{
int n=0;
clrscr();
while(*s!='\0')
{
++n;
++s;
}
return(n);
}
void main(void)
{
char *s;
int l;
clrscr();
printf("\nEnter a string:-");
gets(s);
l=lenght(s);
printf("\nLength of string %s is = %d",s,l);
getch();
}
Output:-
Stud. Riya T 16
Practical 14: write a c program to except the value and display the
address of value by using pointer.
CODE:
#include <stdio.h>
#include<conio.h>
void main()
{
int var = 789;
clrscr();
// pointer for var
int* ptr2;
// double pointer for ptr2
int** ptr1;
// storing address of var in ptr2
ptr2 = &var;
// Storing address of ptr2 in ptr1
ptr1 = &ptr2;
// Displaying value of var using
// both single and double pointers
printf("Value of var = %d\n", var);
printf("Value of var using single pointer = %d\n", *ptr2);
printf("Value of var using double pointer = %d\n", **ptr1);
getch();
}
Output:-
Stud. Riya T 17
Practical 15: write a c program to display the result of student.
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int marks=83;
clrscr();
if(marks>75)
{
printf("first class");
}
else if(marks>65)
{
printf("second class");
}
else if(marks>55)
{
printf("third class");
}
else
{
printf("fouth class");
}
getch();
}
Output:-
Stud. Riya T 18
Practical 16: Write a c program to create store information in text file.
CODE:
#include <stdio.h>
#include<conio.h>
#include <stdlib.h>
void main()
{
char str[1000];
clrscr();
FILE *fptr;
char fname[20]="test.txt";
printf("\n\n Create a file (test.txt) and input text :\n");
printf("----------------------------------------------\n");
fptr=fopen(fname,"w");
if(fptr==NULL)
{
printf(" Error in opening file!");
exit(1);
}
printf(" Input a sentence for the file : ");
fgets(str, sizeof str, stdin);
fprintf(fptr,"%s",str);
fclose(fptr);
printf("\n The file %s created successfully...!!\n\n",fname);
getch();
}
Output:-
Stud. Riya T 19