c lang
c lang
ASSIGNMENT
ON
PC-Software and Multimedia
BACHELOR OF COMPUTER APPLICATIONS
FROM
Pt. Ravishankar Shukla University Raipur (C.G)
Year: 2023-2024
Guided by : Submitted by :
Mr. Mannu Rawani Devesh Chopkar
(HOD computer science) (Class-BCA1)
SUBMITTED TO
Pragati College Raipur (C.G)
Pt. Ravishankar Shukla University Raipur (C.G)
CERTIFICATE OF APPROVAL
2|Page
CERTIFICATE OF EVALUATION
3|Page
DECLARATION
4|Page
ACKNOWLEDEMENT
5|Page
INDEX
S.NO. Program Page
no.
1. Write a program to swap the value of two variables with the help 8
of a third variable.
2. Write a program to swap the value of two variables without 10
using a third variable.
3. Write a program to create equivalent of a four function 12
calculator by using switch statement.
4. Write a program which illustrates the switch statement. 14
5. Write a program to find greatest among three variables. 16
6. Write a program to find greatest among three variables using 18
nested if.
7. Write a program to check whether the given number is even or 20
odd.
8. Write a program to find that the entered year is leap year or not. 21
9. Write a program for estimating simple interest. 23
10. Write a program for estimating compound interest. 25
11. Write a program to check that the given character is vowel or 27
not.
12. Write a program to generate Fibonacci series upto given terms. 28
13. Write a program to find the factorial of a given number. 29
14. Write the program to check given no. is armstrong or not. 30
15. Write a program to count the length of string without using 31
library function.
16. Write a program to find the average of arrays elements. 32
17. Write a program to find the greatest and smallest elements in 34
the one dimensional array.
18. Write a program to access the elements of two dimensional 36
array.
19. Write a program for addition of two matrices. 38
20. Write a program of multiplication of two matrices. 41
21. Write a program of linear search. 44
22. Write a program of bubble sort. 46
23. Write a program to illustrate the use of strlen() function. 48
6|Page
24. Write a program to illustrate the use of strcpy() function. 49
25. Write a program to illustrate the use of strcmp() function. 50
26. Write a program to illustrate the use of strcat() function. 51
27. Write a program to illustrate the use of strrev() function. 52
28. Write a program that calls a function by value. 53
29. Write a program that calls a function by reference 54
30. Write a program to illustrate the use of a structure pointer. 55
31. Write a program to access the element of array using pointer. 56
32. Write a program for declaration and use of pointers to pointers. 57
33. Write a program to illustrate the use of a pointer and string. 58
34. Write a program to illustrate the use of a pointer and function. 59
35. Write a program for no arguments and no return values. 60
36. Write a program for arguments and no return values. 61
37. Write a program for arguments and return values. 63
38. Write a program to demonstrate the use of union. 64
39. Write a program to illustrate the use of structure. 66
40. Write a program to passing structures variable. 68
41. Write a program to returning structures variable. 70
42. Write a program to assign the values a of a structures to another 72
structure.
43. Write a program to compare the values of structure variables. 73
44. Write a program to find the total memory occupied by structure 74
and union variables.
45. Write a program for nested structure. 75
46. Write a program to store records of five students in an array of 77
structures.
47. Write a program to read the content from a file. 79
48. Write a program to copy the content from a file to another file. 80
49. Write a program to write the content to a fille. 81
50. Write a program to use the dynamic memory allocation function. 82
7|Page
Q1. Write a program to swap the value of two variable with the help
of third variable.
Code of Program :
#include<stdio.h>
#include<conio.h>
void main ()
int a,b,c;
clrscr();
scanf("%d", &a);
scanf("%d", &b);
c = a;
a = b;
b = c;
getch();
8|Page
Output of program :
9|Page
Q2. Write a program to swap the value of two variable without the
help of third variable.
Code of program :
#include<stdio.h>
#include<conio.h>
void main()
int a,b;
clrscr();
scanf("%d", &a);
scanf("%d", &b);
a=a+b;
b=a-b;
a=a-b;
getch();
10 | P a g e
Output :
11 | P a g e
Q3. Write a program to create equivalent of a four function calculator
by using switch statement.
Code of program :
#include <stdio.h>
#include <conio.h>
void main() {
char op;
scanf("%c", &op);
switch (op) {
case '+':
break;
case '-':
12 | P a g e
break;
case '*':
break;
case '/':
break;
default:
getch();
Output :
13 | P a g e
Q4. Write a program which illustrates the switch statement.
Code of Program :
#include <stdio.h>
#include <conio.h>
void main()
char lang ;
scanf("%s",&lang);
switch(lang) {
case 'e':
break;
case 'f':
printf("\n Bonjour");
break;
default:
printf("Invalid input");
break;
getch();
14 | P a g e
Output :
15 | P a g e
Code of Program :
#include <stdio.h>
#include <conio.h>
void main()
int a, b, c,flag=1;
scanf("%d", &a);
printf("b: ");
scanf("%d", &b);
printf("c: ");
scanf("%d", &c);
flag=0;
flag=0;
flag=0;
if (flag==1)
16 | P a g e
getch();
Output :
17 | P a g e
Code of Program :
#include <stdio.h>
#include <conio.h>
void main() {
scanf("%f", &n1);
scanf("%f", &n2);
scanf("%f", &n3);
18 | P a g e
getch();
Output :
19 | P a g e
Code of Program :
#include <stdio.h>
#include <conio.h>
void main() {
int num;
scanf("%d", &num);
if(num % 2 == 0)
else
getch();
Output :
Code of Program :
20 | P a g e
#include <stdio.h>
#include <conio.h>
void main() {
int year;
scanf("%d", &year);
if (year % 400 == 0) {
else if (year % 4 == 0) {
else {
getch();
Output :
21 | P a g e
22 | P a g e
Q9. Write a program for estimating simple interest.
Code of Program :
# include <conio.h>
# include <stdio.h>
# include <conio.h>
void main(){
scanf("%f", &principal);
scanf("%f", &rate);
scanf("%f", &time);
getch();
23 | P a g e
Output :
24 | P a g e
Q10. Write a program for estimating compound interest.
Code of Program :
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
scanf("%f", &principle);
scanf("%f", &time);
scanf("%f", &rate);
25 | P a g e
getch();
Output :
26 | P a g e
Q11. Write a program to check that given character is Vowel or not.
Code of Program :
#include <stdio.h>
#include <conio.h>
void main() {
char c;
scanf("%c", &c);
if (lowercase_vowel || uppercase_vowel)
else
getch();
Output :
27 | P a g e
Q12. Write a program to generate fibonacci series upto given terms.
Code of Program :
#include <stdio.h>
#include <conio.h>
void main()
scanf("%d",&n);
for (i=0;i<n;i++)
{sum=a+b;
printf("\t%d",sum);
a=b;
b=sum;}
getch();
Output :
28 | P a g e
Q13. Write a program to find the factorial of a given number.
Code of Program :
#include <stdio.h>
#include <conio.h>
void main() {
int i, fact=1,n;
scanf("%d", &n);
{ fact= i*fact ;
getch();
Output :
29 | P a g e
Q14.Write a Program to check the given no. is Armstrong or not.
Code of Program :
#include <stdio.h>
#include <conio.h>
void main() {
scanf("%d", &num);
originalNum = num;
while (originalNum != 0) {
originalNum /= 10;
if (result == num)
else
getch();
30 | P a g e
Q15. Write a program to calculate to count the length of a string
without using library function.
Code of Program :
#include <stdio.h>
#include <conio.h>
void main()
char str[100];
int i,length=0;
scanf("%s",str);
length++;
getch();
31 | P a g e
Q16. Write a program to find the average of arrays elements.
Code of Program :
#include <stdio.h>
#include <conio.h>
void main() {
int n, i;
scanf("%d", &n);
scanf("%d", &n);
scanf("%f", &num[i]);
sum += num[i];
avg = sum / n;
32 | P a g e
printf("Average = %.2f", avg);
getch();
Output :
33 | P a g e
Q17. Write a program to find the largest and smallest elements in the
one dimensional array.
Code of Program :
#include<stdio.h>
#include<conio.h>
void main()
int a[50],i,n,large,small;
scanf("%d", &n);
for(i=0;i<n;++i)
scanf("%d",&a[i]);
large=small=a[0];
for(i=1;i<n;++i)
if(a[i]>large)
large=a[i];
if(a[i]<small)
small=a[i];
34 | P a g e
printf("\nThe smallest element is %d\n",small);
getch();
Output :
35 | P a g e
Q18. Write a program to access the elements of two dimensional
array.
Code of Program :
#include<stdio.h>
#include <conio.h>
void main(){
int i=0,j=0;
int arr[4][3]={{1,2,3},{2,3,4},{3,4,5},{4,5,6}};
for(i=0;i<4;i++){
for(j=0;j<3;j++){
} }
getch();
Output :
36 | P a g e
37 | P a g e
Q19. Write a program for addition of two marices.
Code of Program :
#include <stdio.h>
#include <conio.h>
int main() {
scanf("%d", &r);
scanf("%d", &c);
scanf("%d", &a[i][j]);
scanf("%d", &b[i][j]);
38 | P a g e
for (j = 0; j < c; ++j) {
if (j == c - 1) {
printf("\n\n");
getch();
39 | P a g e
Program :
40 | P a g e
Q20. Write a program for multiplication of two marices.
Code of Program :
#include<stdio.h>
#include <conio.h>
#include<stdlib.h>
void main(){
int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;
system("cls");
scanf("%d",&r);
scanf("%d",&c);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",&a[i][j]);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
41 | P a g e
{
scanf("%d",&b[i][j]);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
mul[i][j]=0;
for(k=0;k<c;k++)
mul[i][j]+=a[i][k]*b[k][j];
for(i=0;i<r;i++)
for(j=0;j<c;j++)
printf("%d\t",mul[i][j]);
printf("\n");
42 | P a g e
}
getch();
Output :
43 | P a g e
Q21. Write a program of linear search.
Code of Program :
#include <stdio.h>
#include <conio.h>
void main()
scanf("%d", &n);
scanf("%d", &array[c]);
scanf("%d", &search);
if (array[c] == search {
break;
44 | P a g e
}
if (c == n)
getch();
Output :
45 | P a g e
Q22. Write a program of Bubble sort.
Code of Program :
#include<stdio.h>
#include <conio.h>
{ int i;
{ printf("%d ",a[i]);
int i, j, temp;
{ temp = a[i];
a[i] = a[j];
a[j] = temp;
46 | P a g e
}
void main ()
int i, j,temp;
int n = sizeof(a)/sizeof(a[0]);
print(a, n);
bubble(a, n);
print(a, n);
getch();
Output :
47 | P a g e
Q23. Write a code to illustrate the use of of strlen() function.
Code of Program :
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
int length=strlen(name);
getch();
Output :
48 | P a g e
Q24. Write a code to illustrate the use of of strcpy() function.
Code of Program :
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main() {
char college[10];
char area[10]="pragati";
strcpy(college, area);
getch();
Output :
49 | P a g e
Q25. Write a code to illustrate the use of of strcmp() function.
Code of Program :
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main() {
if (result == 0) {
} else {
getch();
Output :
50 | P a g e
Q26. Write a program to illustrate the use of strcat() function.
Code of Program :
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main() {
char str1[10]="hello";
char str2[20]="everyone";
strcat(str1, str2);
printf("%s", str1);
getch();
Output :
51 | P a g e
Q27. Write a program to illustrate the use of strrev() function.
Code of Program :
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main()
char name[10]="anurag";
getch();
Output :
52 | P a g e
Q28. Write a program that calls a function by value.
Code of Program:
#include <stdio.h>
#include <conio.h>
int main(){
int n;
scanf("%d",&n);
square(n);
getch();
n=n*n;
Output :
53 | P a g e
Q29. Write a program that calls a function by refrence.
Code of Program :
#include <stdio.h>
#include <conio.h>
voidmain(){
int n;
scanf("%d",&n);
square(n);
getch();
n=n*n;
Output :
54 | P a g e
Q30. Write a program to illustrate the use of structure pointer.
Code of Program :
#include <stdio.h>
#include <conio.h>
struct student{
char name[10];
int age;
};
void main(){
p=&s1;
getch();
Output :
55 | P a g e
Q31. Write a program to access the element of array using pointer.
#include <conio.h>
void main ()
int *ptr = p;
getch();
Output:
56 | P a g e
Q32. Write a program for declaration and use of pointer to pointer.
Code of Program:
#include <stdio.h>
#include <conio.h>
void main(){
int a=20;
int *p,**pp;
p=&a; pp=&p;
getch();
Output:
57 | P a g e
Q33. Write a program to illustrate the use of pointer and string.
Code of Program:
#include <stdio.h>
voidmain()
char str[20];
char *p;
p=str;
while(*p!='\0')
printf("%c",*p++);
getch();
Output:
58 | P a g e
Q34. Write a program to illustrate the use of pointer and function.
Code of Program:
#include <stdio.h>
#include <conio.h>
void main()
{ int x,y;
x=10;
y=20;
swap(&x, &y);
getch();
int t;
t=*a;
*a=*b;
*b=t;}
Output:
59 | P a g e
Q35. Write a program for no arguments and no returns.
Code of Program:
#include <stdio.h>
#include <conio.h>
void about_myself();
void main()
about_myself();
getch();
void about_myself(){
Output :
60 | P a g e
Q36. Write a program for arguments and no return values.
Code of Program:
#include<stdio.h>
#include<conio.h>
void division(int,int);
void main()
{ int a,b;
scanf("%d %d",&a,&b);
division(a,b);
getch();
int c;
c=x/y;
61 | P a g e
Output:
62 | P a g e
37. Write a program for arguments and return value.
Code of Program:
#include <stdio.h>
#include <conio.h>
{ int c;
c = x * y;
return c;
void main()
int a = 10, b = 5;
int c = product(a,b);
getch();
Ouput :
63 | P a g e
Q38. Write a program to demonstrate the uses of union.
Code of Program:
#include <stdio.h>
#include <conio.h>
union student {
float marks;
char name[15];
};
void main()
scanf("%s",&u1.name);
scanf("%f",&u1.marks);
getch();
64 | P a g e
Output :
65 | P a g e
Q39. Write a program to illustrate the use of structure.
Code of Program:
#include <stdio.h>
#include <conio.h>
#include <string.h>
struct student {
char name[20];
int age;
};
void main()
scanf("%s",&s1.name);
scanf("%d",&s1.age);
getch();
66 | P a g e
Output :
67 | P a g e
Q40. Write a program to passing structures variable.
Code of Program:
#include <string.h>
#include <conio.h>
#include <stdio.h>
struct student
int id;
char name[20];
float percentage;
};
void main()
record.id=1;
strcpy(record.name, "Raju");
record.percentage = 86.5;
func(record);
getch();
68 | P a g e
{
Output :
69 | P a g e
Q41. Write a program to return structure variables
Code of Program :
#include <stdio.h>
struct student {
char name[20];
int age;
float marks;
};
struct student s;
scanf("%s", s.name);
scanf("%d", &s.age);
scanf("%f", &s.marks);
return s;
int main()
70 | P a g e
printf("Marks: %.1f\n", s1.marks);
return 0;
Output:
71 | P a g e
Q42. Write a program to assign the values of structure to another
structure.
Code of Program:
#include <stdio.h>
#include <string.h>
#include <conio.h>
int citypin;
float bill_amt;
} person1, person2;
void main() {
strcpy(person1.name, "pyarelal");
person1.citypin = 501;
person2 = person1;
getch();}
Output :
72 | P a g e
Q43. Write a program to compare the value of structure variables.
Code of Program:
#include <stdio.h>
#include <conio.h>
struct Point {
int x;
int y;
};
voidmain() {
} else {
getch();
Output:
73 | P a g e
Q44. Write a program to find the total memory occupied by structure
and union variable.
Code of Program:
#include <stdio.h>
#include <conio.h>
struct s_tag
{int a;
long int b;
} x;
union u_tag
int a;
long int b;
} y;
void main()
getch();
} Output:
74 | P a g e
Q45. Write a program for nested structure.
Code of Program:
#include<stdio.h>
struct address
char city[20];
int pin;
char phone[14];
};
struct employee
char name[20];
};
void main ()
75 | P a g e
Output:
76 | P a g e
Q46. Write a program to store records of five students in an array of
structure.
Code of Program:
#include<stdio.h>
#include<conio.h>
struct student {
char name[20];
int age;
};
void main()
printf("Name: ");
scanf("%s", bca[i].name);
printf("Age: ");
scanf("%d", &bca[i].age);
printf("\n");
77 | P a g e
printf("Age: %d\n", bca[i].age);
printf("\n");
getch();
Output:
78 | P a g e
Q47. Write a program to read the content from a file.
Code of Program:
#include <stdio.h>
#include <conio.h>
Void main()
FILE* fp;
char ch;
fp = fopen("abc.txt", "r");
ch=fgetc(fp);
while(ch!=EOF)
printf(“%c”,ch);
ch=fgetc(fp);
fclose(fp);
getch();
Output:
79 | P a g e
Q48. Write a program to copy the content from one file to another
file.
Code of Program:
#include <stdio.h>
#include <conio.h>
Void main()
{
FILE *fp1,*fp2;
charch;
fp1 =fopen("hello.txt","r");
fp2 =fopen("xyz.txt","w");
while((ch=getc(fp1))!=EOF)
{
putc(ch, fp2);
}
fclose(fp1);
fclose(fp2);
}
Output:
80 | P a g e
Q49. Write a program to write the content to a file.
Code of Program:
#include <stdio.h>
#include <conio.h>
void main()
FILE *fp;
char content[500];
fp = fopen("abc.txt", "w");
scanf("%s",content);
fprintf(fp,"%s",content);
fclose(fp);
getch():
Output:
81 | P a g e
Q50. Write a program to use the dynamic memory allocation function.
Code of Program:
Malloc()
#include<stdio.h>
#include<conio.h>
voidmain(){
int n,i,*ptr,sum=0;
scanf("%d",&n);
ptr=(int*)(n*sizeof(int));
if(ptr==NULL)
for(i=0;i<n;++i)
scanf("%d",ptr+i);
sum+=*(ptr+i);
printf("Sum=%d",sum);
free(ptr);
getch();}
82 | P a g e
Output:
Calloc()
#include<stdio.h>
#include<conio.h>
voidmain(){
int n,i,*ptr,sum=0;
scanf("%d",&n);
ptr=(int*)calloc(n,sizeof(int));
if(ptr==NULL)
exit(0);
83 | P a g e
printf("Enter elements : ");
for(i=0;i<n;++i)
scanf("%d",ptr+i);
sum+=*(ptr+i);
printf("Sum=%d",sum);
free(ptr);
getch();
Output:
Realloc
#include <stdio.h>
#include <conio.h>
voidmain() {
84 | P a g e
int *ptr = (int*) realloc(3 * sizeof(int));
ptr[0] = 10;
ptr[1] = 20;
ptr[2] = 30;
free(ptr);
getch();
Output:
Free()
#include <stdio.h>
#include <conio.h>
voidmain()
85 | P a g e
int *ptr, *ptr1;
int n, i;
n = 5;
exit(0);
else {
free(ptr);
free(ptr1);
getch();
86 | P a g e
Output :
87 | P a g e
88 | P a g e