0% found this document useful (0 votes)
99 views95 pages

C Practical by Janak Sahu

This document is a submission by Janak Sahu of Vivekanand Mahavidyalaya, Raipur for the partial fulfillment of requirements for a Bachelor of Computer Application degree from Pt. Ravishankar Shukla University, Raipur. It contains 85 programs written in C language covering topics like arithmetic operations, loops, arrays, strings, structures, files and functions. Each program is numbered and signed by Janak Sahu along with the page number. The programs solve problems ranging from basic calculations to more advanced concepts in programming. The document is guided by the head of the computer science department, Mr. Nishid Parmar.

Uploaded by

shuklauday2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views95 pages

C Practical by Janak Sahu

This document is a submission by Janak Sahu of Vivekanand Mahavidyalaya, Raipur for the partial fulfillment of requirements for a Bachelor of Computer Application degree from Pt. Ravishankar Shukla University, Raipur. It contains 85 programs written in C language covering topics like arithmetic operations, loops, arrays, strings, structures, files and functions. Each program is numbered and signed by Janak Sahu along with the page number. The programs solve problems ranging from basic calculations to more advanced concepts in programming. The document is guided by the head of the computer science department, Mr. Nishid Parmar.

Uploaded by

shuklauday2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 95

A

Practical based

On

Programming in C Language (107)


Submitted in partial fulfillment of requirement of

Bachelor of Computer Application

BCA Ist
FROM

Pt. Ravishankar Shukla University, Raipur (C.G.)

Session 2022-2023

Guided By: Submitted By:


Mr. Nishid Parmar Janak Sahu
(Head of department)
Dept. of Computer Science

Submitted
To
Vivekanand Mahavidyalaya, KK Road Raipur
S.NO PROGRAMS PAGE NO. SIGNATURE
1. Write a Program to add two numbers. 1

2. Write a Program to perform arithmetic 2


operation in C language.
3. Write a Program to calculate simple interest. 3
4. Write a program to convert celcius to Fahrenheit. 4
5. Write a program to convert Fahrenheit to celcius. 5
6. Write a program to add first and last digit of Four-digit 6
number.
7. Write a program to calculate average rainfall during the year 7
2022.
8. Write a program to swap the value of two variables. 8
9. write a program to calculate percentage 0f students of 5 9
subjects.
10. Write a program to calculate area of circle. 10
11. Write a program to calculate area of triangle. 11
12. Write a program to calculate area of rectangle. 12
13. Write a program to calculate area of square. 13
14. write a program to calculate maximum number of two 14
numbers.
15. write a program to check whether the entered year is leap 15
year or not.
16. write a program to check whether the entered number is even 16
or odd.
17. write a program to check whether the entered number is even 17
or not.
18. Write a program to calculate maximum numbers of three 18
numbers.
19. Write a program using switch case to print color. 19
20. Write a program to print grade of students according to their 20
marks.
21. Write a program using switch case to print week days 21-22
according to numbers.
22. Write a program to check whether an entered character is a 23-24
vowel or consonant.
23. Write a program using switch case to perform arithmetic 25-26
operation according to user choice.
24. Write a program to print the series of natural number from 1 27
to 10 using loop.
25. Write a program to print the series of following series (2, 1, 4 28
,3,6 ,5 ,8 ,7, . . . ).
26. Write a program to print the series of following series 29
(1,4,9,16,25, . . .100).
27. Write a program to print 1 to 10 using while loop. 30
28. Write a program to print even number between 2 to 20. 31
29. Write a program to print 1 to 10 in reverse order. 32
30. Write a program to print odd number between 1 to 19. 33
31. Write a program to print a table of any number user. 34
32. Write a program to check Armstrong number. 35
33. Write a program to print sum of first 10 natural number. 36
34. Write a program to print numbers from 1 to 10. 37
35. Write a program to check prime number. 38
36. Write a program to print series 0,1,1,2,3,5,8…. 39
37. Write a program to print power square. 40
38. Write a program to print all the combination of the number 41
1,2,3.
39. Write a program to print the (*) patern in increasing order. 42
40. Write a program to print the (*) patern in decreasing order. 43
41. Write a program to print the number patern in 44
increasing order.
42. Write a program to print the number patern in 45
decreasing order.
43. Write a program to print break function. 46
44. Write a program to print continue function. 47
45. Write a program to print factorial function. 48
46. Write a program to create a function of addition of 2 numbers 49
with return value. (call by value).
47. Write a program to create a function of addition of 2 numbers 50
without return value. (Call by value).
48. Write a program to calculate simple interest using function 51
with return value. (Call by value).
49. Write a program to calculate simple interest using function 52
without return value. (Call by value).
50. Write a program to calculate factorial number using function 53
with return value. (call by value).
51. Write a program to calculate factorial number using function 54
without return value. (Call by value).
52. Write a program to swapping using functions. 55
53. Write a program to print power square using pow () function. 56
54. Write a program to calculate power using function with return 57
value. (Call by value).
55. Write a program to calculate power using function without 58
return value. (Call by value).
56. Write a program to create a function of addition of 2 numbers 59
with return value. (Call by address).
57. Write a program to create a function of addition of 2 numbers 60
without return value. (Call by address).
58. Write a program to calculate simple interest using function 61
with return value. (Call by address).
59. Write a program to calculate simple interest using function 62
without return value. (Call by address).
60. Write a program to calculate factorial using function with 63
return value. (Call by address).
61. Write a program to calculate factorial using function without 64
return value. (Call by address).
62. Write a program to calculate power using function with return 65
value. (Call by address).
63. Write a program to calculate power using function without 66
return value. (Call by address).
64. Write a program to calculate factorial using recursion. 67
65. Write a program to take 5 values in an array and print those 68
five values.
66. Write a program to take 10 values in an array and print values. 69
67. Write a program to take 10 elements in an array and search 70
the given number present in an array or not.
68. Write a program to find maximum number in an array of 10 71
elements.
69. Write a program to find minimum number in an array of 10 72
elements.
70. Write a program to take 5 elements in an array and sort then 73
in descending order.
71. Write a program to take 5 elements in an array and sort then 74
in ascending order.
72. Write a program to multiplication of two matrix. 75-76
73. Write a program to addition of two matrix. 77-78
74. Write a program to subtraction of two matrix. 79-80
75. Write a program to take 9 elements in a 2-dimensional array 81
of matrix 3*3.
76. Write a program to take one string and print that string. 82
77. Write a program to check whether a string is 83
palindrome or not.
78. Write a program to concatenate two strings. 84
79. Write a program to copy one string into another string. 85
80. Write a program to perform pointer arithmetic. 86
81. Write a program to create structure that take roll no. and 87
name of student. (Structure).
82. Write a program to create structure that take roll no. and 88
name of student. (Union).
83. Write a program to demonstrate pointer in array. 89
84. Write a program to copy the content of one file into another. 90
85. Write a program to append a content of one file into another 91
file.
BCA I

PROGRAM -1
Write a Program to add two numbers.
Program:-
#include<stdio.h>
#include<conio.h>
void main ( )
{
int a, b, c ;
printf (“Enter value of a and b”);
scanf (“%d%d”, &a , &b);
c=a+b;
printf (“addition of a + b = %d” , c );
getch ( );
}
OUTPUT:-

Janak Sahu Page |1


BCA I

PROGRAM- 2
Write a Program to perform arithmetic operation in C
language.

Program:-
#include<stdio.h>
#include<conio.h>
void main ( )
{
int a, b, c, d, e, f ;
printf (“enter value of a and b”);
scanf (“ %d%d” , &a , &b);
c=a+b;
d=a–b;
e=a*b;
f=a/b;
printf (“ \n Addition of a + b =%d” , c);
printf (“ \n Subtraction of a – b =%d” , d);
printf (“ \n Multiplication of a * b =%d” , e);
printf (“ \n Division of a / b =%d” , f );
getch ( );
}
OUTPUT:-

Janak Sahu Page |2


BCA I

PROGRAM -3
Write a Program to calculate simple interest.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int p , r , t, si ;
printf (“enter value of p, r, t”);
scanf (“%d , %d , %d” , &p , &r , &t);
si = (p * r * t) / 100 ;
printf (“simple interest = %d” , si);
getch ( );
}
OUTPUT:-

Janak Sahu Page |3


BCA I

PROGRAM-4
Write a program to convert celcius to Fahrenheit.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int c , f ;
clrscr ( ) ;
printf (“Enter value of c”);
scanf (“%d” , &c);
f = (c*9/5) + 32 ;
printf (“f = %d” , f );
getch ( );
}

OUTPUT:-

Janak Sahu Page |4


BCA I

PROGRAM -5
Write a program to convert Fahrenheit to celcius.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
float f , c ;
printf (“enter value of f ”);
scanf (“%f ” , &f );
c = 5/9 * (f- 32) ;
printf (“c = %f ” , c);
getch ( );
}

OUTPUT:-

Janak Sahu Page |5


BCA I

PROGRAM -6
Write a program to add first and last digit of
Four digit number.
Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n , a , b ;
printf (“enter four digits\n”);
scanf (“%d” , &n);
a = n / 1000 ;
b = n % 10 ;
printf (“%d” , a + b);
getch ( );
}

OUTPUT:-

Janak Sahu Page |6


BCA I

PROGRAM -7
Write a program to calculate average rainfall during the
year 2020.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int Jan, feb, mar, April, may, Jun, jul, Aug, sep, oct , nov, dec ;
float Average ;
printf (“Enter value of jan , feb , mar , apr , may , jun , jul , aug , sep , oct , nov ,
dec”);
scanf (“%d %d %d %d %d %d %d %d %d %d %d %d” , &jan , &feb , &mar ,
&apr , &may , &jun , &jul , &aug , &sep , &oct , &nov , &dec);
Average =( jan+feb+mar+apr+may+jun+jul+aug+sep+oct+nov+dec ) / 12 ;
printf = (“Average = %f ” , Average);
getch ( );
}

OUTPUT:-

Janak Sahu Page |7


BCA I

PROGRAM -8
Write a program to swap the value of two variables.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int a , b , c ;
printf (“Enter value of a and b”);
scanf (“%d , %d” , &a , &b);
c=a;
a=b;
b=c;
printf (“%d , %d” , a , b);
getch ( );
}

OUTPUT:-

Janak Sahu Page |8


BCA I

PROGRAM -9
Write a program to calculate percentage 0f students of 5
subjects.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int a , b , c , d , e , percentage ;
printf (“Enter the value of a , b , c , d , e”);
scanf (“%d%d%d%d%d , &a , &b , &c , &d , &e”);
percentage = ( a + b + c + d + e ) * 100 / 500;
printf (“percentage of students =%d” , percentage);
getch ( );
}

OUTPUT:-

Janak Sahu Page |9


BCA I

PROGRAM -10
Write a program to calculate area of circle.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int radius , area ;
printf (“enter radius of circle \n”);
scanf (“%d” , &radius);
Area = 3.14 * radius * radius ;
printf (“Area of circle = %d \n ” , Area);
getch ( );
}

OUTPUT:-

Janak Sahu P a g e | 10
BCA I

PROGRAM -11
Write a program to calculate area of triangle.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
float base , height , area ;
printf (“enter base in centimeter :”);
scanf (“%f ” , &base);
printf (“enter height in centimeter :”);
scanf(“%f ” , &height);
Area = ( base * height )/2;
printf (“area of triangle=%f ” , area );
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 11
BCA I

PROGRAM -12
Write a program to calculate area of rectangle.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
float length , breadth , area ;
printf (“enter length in centimeter”);
scanf (“%f ” , &length);
printf (“enter breadth in centimeter”);
scanf (“%f ” , &breadth);
Area = length * breadth;
printf (“Area of reactangle = %f ” , area);
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 12
BCA I

PROGRAM -13
Write a program to calculate area of square.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
float length , area ;
printf (“enter length in centimeter”);
scanf (“%f ” , &length);
Area = length * length ;
printf (“Area of square = %f ” , area );
getch ( );
}

OUTPUT:-

Janak Sahu P a g e | 13
BCA I

PROGRAM -14
Write a program to calculate maximum number of two
numbers.

Program:
#include <stdio.h>
#include <conio.h>
void main ( )
{
int a , b ;
printf (“Enter two numbers”);
scanf (“%d , %d” , &a , &b);
if (a>b)
{
printf (“a is maximum”);
}
else
{
printf (“b is maximum”);
}
getch( );
}
OUTPUT:

Janak Sahu P a g e | 14
BCA I

PROGRAM -15
Write a program to check whether the entered year is leap
year or not.

Program:
#include <stdio.h>
#include <conio.h>
void main ( )
{
int year ;
printf (“Enter a leap year to check if it is a leap year\n”);
scanf (“%d” , &year);
if (year % 400==0)
printf (“%d is a leap year.\n” , year);
else if (year % 100==0)
printf (“%d is not a leap year.\n” , year);
else if (year % 4==0)
printf (“%d is a leap year.\n” , year);
else
printf (“%d is not a leap year.\n” , year);
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 15
BCA I

PROGRAM -16
Write a program to check whether the entered number is
even or odd.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n ;
printf (“Enter any number”);
scanf (“%d” , &n);
if (n % 2= = 0)
{
printf (“ It is an even number\n”);
}
else
{
printf (“ It is an odd number \n”);
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 16
BCA I

PROGRAM -17
Write a program to check whether the entered number is
even or not.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n ;
printf (“Enter any number”);
scanf (“%d” , &n);
if (n % 2= = 0)
{
printf (“ It is an even number\n”);
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 17
BCA I

PROGRAM -18
Write a program to calculate maximum numbers of three
numbers.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int a , b , c ;
printf (“Enter three numbers”);
scanf (“%d , %d , %d” , &a , &b , &c);
if (a>b)
{
if (a>c)
{
printf (“a is maximum”);
}
else
printf (“c is maximum”);
}
else
{
If (b>c)
printf (“b is maximum”);
else
printf (“c is maximum”);
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 18
BCA I

PROGRAM -19
Write a program using switch case to print color.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n ;
printf (Enter value of n”);
scanf (“%d” , &n);
switch (n)
{
case 1 :
printf (“BLUE”);
break ;
case 2 :
printf (“BLACK”);
break ;
case 3 :
printf (“CYAN”);
break ;
case 4 :
printf (“RED”);
break ;
case 5 :
printf (“MAGENTA”);
break ;
default :
printf (“invalid”);
break ;
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 19
BCA I

PROGRAM -20
Write a program to print grade of students according to
their marks.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int percentage ;
printf (“enter percentage”);
scanf (“%d” , &per);
if (per>80)
printf (“grade A”);
else if (( per >=60) && (per<=79))
printf (“grade B”);
else if ((per>=50) && (per<=59))
printf (“grade C”);
else if ((per >=40) && (per<=49))
printf (“grade D”);
else if (per<=40)
printf (“fail”);
getch ();
}
OUTPUT:-

Janak Sahu P a g e | 20
BCA I

PROGRAM -21
Write a program using switch case to print week days
according to numbers.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n ;
printf (“enter value of n”);
scanf (“%d” , &n);
switch (n)
{
case 1 :
printf (“monday”);
break ;
case 2 :
printf (“tuesday”);
break ;
case 3 :
printf (“wednesday”);
break ;
case 4 :
printf (“thursday”);
break ;
case 5 :
printf (“friday”);
break ;
case 6 :
printf (“saturday”);
break ;
case 7 :
printf (“sunday”);
break ;
default :
printf (“invalid”);
break ;
}
getch ( );
}

Janak Sahu P a g e | 21
BCA I

OUTPUT:-

Janak Sahu P a g e | 22
BCA I

PROGRAM -22
Write a program to check whether an entered character is
a vowel or consonant.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
char alphabet ;
printf (“Enter an alphabet character :”);
scanf (“%c” , &alphabet);
switch (alphabet)
{
Case ‘ a ’ :
printf (“vowel”);
break;
Case ‘ e ’ :
printf (“vowel”);
break;
Case ‘ i ’ :
printf (“vowel”);
break;
Case ‘ o ’ :
printf (“vowel”);
break;
Case ‘ u ’ :
printf (“vowel”);
break;
Case ‘ A ’ :
printf (“vowel”);
break;
Case ‘ E ’ :
printf (“vowel”);
break;
Case ‘ I ’ :
printf (“vowel”);
break;
Case ‘ O ’ :
printf (“vowel”);
break;
Case ‘ U ’ :
printf (“vowel”);
break;
default :
printf (“consonant”);
}
getch ( );
}

Janak Sahu P a g e | 23
BCA I

OUTPUT:-

Janak Sahu P a g e | 24
BCA I

PROGRAM -23
Write a program using switch case to perform arithmetic
operation according to user choice.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int a , b , ch , Addition , Subtraction , Multiplication , Division ;
printf (“enter value of a and b”);
scanf (“%d , %d , &a , &b”);
printf (“ \n1 Addition \n 2 Subtraction \n 3Multiplication
\n 4 Division ”);
printf (“\n enter your choice”);
scanf (“%d” , &ch);
switch (ch)
{
case 1 :
Addition = (a + b);
printf (“%d” , Addition);
break ;
case 2 :
Subtraction = (a - b);
printf (“%d”, Subtraction);
break ;
case 3 :
Multiplication = (a / b);
printf (“%d” , Multiplication);
break ;
case 4 :
Division = (a * b);
printf (“%d” , Division);
break ;
default :
printf (“invalid”);
break ;
}
getch ( );
}

Janak Sahu P a g e | 25
BCA I

OUTPUT:-

Janak Sahu P a g e | 26
BCA I

PROGRAM -24
Write a program to print the series of natural number
from 1 to 10 using loop.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int i ;
printf (“print natural numbers from 1 to 10 \n”);
for (i = 1 ; i < = 10 ; i++)
{
printf (“%d \n” , i);
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 27
BCA I

PROGRAM -25
Write a program to print the series of following series.
(2 , 1 , 4 , 3 , 6 , 5 , 8 , 7 , . . . )
Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n , b ;
printf (“print the series\n”);
for (n = 2 ; n < = 20 ; n = n + 2 )
{
b=n–1;
printf (“\n%d\n%d” , n , b);
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 28
BCA I

PROGRAM -26
Write a program to print the series of following series.
(1 , 4 , 9 , 16 , 25 , . . . 100)
Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int I ;
printf (“print the series\n”);
for (I = 1 ; I < = 10 ; I + +)
{
printf (“%d\n” , i*i);
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 29
BCA I

PROGRAM -27
Write a program to print 1 to 10 using while loop.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int i ;
printf (“print numbers from 1 to 10\n”);
i=1;
while (i<=10)
{
printf (“\n%d”,i);
i++ ;
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 30
BCA I

PROGRAM -28
Write a program to print even number between 2 to 20.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int i ;
printf (“Print even numbers between 2 to 20\n”);
printf (“Even numbers :\n”);
for (i = 2 ; i < = 20 ; i = i + 2 )
{
printf (“%d \n” , i );
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 31
BCA I

PROGRAM:-29
Write a program to print 1 to 10 in reverse order.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int i , n ;
printf (“print numbers from 1 to 10 in reverse order\n”);
i = 10 ;
do
{
printf (“%d \n”, i);
i--;
}
while (i > = 1);

getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 32
BCA I

PROGRAM -30
Write a program to print odd number between 1 to 19.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int i ;
printf (“print odd numbers between 1 to 19\n”);
printf (“odd numbers:\n”);
for (i = 1 ; i<=20 ; i = i+2)
{
printf (“%d\n” , i);
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 33
BCA I

PROGRAM -31
Write a program to print a table of any number by user.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n , I ;
printf (“Enter a number”);
scanf(“%d” , &n);
for ( I = 1 ; I < = 10 ; I + +)
{
printf (“%d * %d = %d\n” , n , I , n * I );
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 34
BCA I

PROGRAM -32
Write a program to check Armstrong number.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n , r , s = 0 , t ;
printf (“Enter any number”);
scanf (“%d” , &n);
t=n;
while (n ! = 0)
{
r = n % 10 ;
s = s + (r * r * r);
n = n / 10;
}
if (t = = s)
printf (“It is a armstrong number”);
else
printf (“ It is not a armstrong number”);
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 35
BCA I

PROGRAM -33
Write a program to print sum of first 10 natural number.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n , i , sum = 0 ;
printf (“Enter Natural numbers from 1 to 10”);
scanf (“%d” , &n);
for (i = 1 ; i < = 10 ; i + +)
{
Sum = sum + i ;
}
printf (“sum = %d” , sum);
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 36
BCA I

PROGRAM -34
Write a program to print numbers from 1 to 10.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int i ;
printf (“print numbers from 1 to 10\n”);
i=1;
do
{
printf (“%d\n” ,i );
i++;
}
while ( i< = 10);

getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 37
BCA I

PROGRAM -35
Write a program to check prime number.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n , i , s = 0 ;
printf (“Enter any number\n”);
scanf(“%d” , &n );
for (i = 2 ; i < n ; i + +)
{
if (n % i = = 0)
{
s=1;
}
}
if (s = = 0)
printf( “It is a prime number” );
else
printf ( “It is not a prime number” );
getch( );
}
OUTPUT:-

Janak Sahu P a g e | 38
BCA I

PROGRAM -36
Write a program to print series 0,1,1,2,3,5,8….

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int a = 0 , b = 1 , c , i , n ;
printf (“Enter number of term to print ”);
scanf (“%d” , &n);
printf(“\n%d\n%d” , a , b );
for ( i = 1; i < = n-2; i + + )
{
c=a+b;
printf (“\n%d” , c);
a=b;
b=c;
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 39
BCA I

PROGRAM -37
Write a program to print power square.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int a , b, i , result = 1 ;
printf (“Enter a number”);
scanf (“%d” , &a);
printf (“”Enter power number”);
scanf (“%d” , &b);
for (i = 1; i< = b; i + +)
{
Result = result * a ;
}
printf (“%d” , result );
getch( );
}
OUTPUT:-

Janak Sahu P a g e | 40
BCA I

PROGRAM -38
Write a program to print all the combination of the
number 1,2,3 .

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int i , j , k ;
for (i = 1 ; i < = 3 ; i + +)
{
for (j = 1 ; j < = 3 ; j + +)
{
for (k = 1 ; k < = 3 ; k + +)
{
printf (“%d%d%d\n” , i , j , k);
}
}
}
getch( );
}
OUTPUT:-

Janak Sahu P a g e | 41
BCA I

PROGRAM -39
Write a program to print the ( * ) pattern in increasing
order.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int i , j ;
printf (“Print a pattern in star series”);
for (i = 1 ; i < = 5 ; i + +)
{
for (j = 1 ; j < = i ; j + +)
{
printf ( “ * ”);
}
printf (“\n”);
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 42
BCA I

PROGRAM -40
Write a program to print the ( * ) pattern in decreasing
order.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int i , j ;
printf (“Print a pattern in star series”);
for (i = 1 ; i < = 5 ; i + +)
{
for (j = i ; j < = 5 ; j + +)
{
printf ( “ * ”);
}
printf (“\n”);
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 43
BCA I

PROGRAM -41
Write a program to print the number pattern in
increasing order.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int i , j ;
printf (“Print a pattern in number series”);
for (i = 1 ; i < = 5 ; i + +)
{
for (j = 1 ; j < = i ; j + +)
{
printf (“ %d ” , j );
}
printf (“\n”);
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 44
BCA I

PROGRAM -42
Write a program to print the number pattern in
decreasing order.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int i , j ;
printf (“Print a pattern in number series”);
for (i = 1 ; i < = 5 ; i + +)
{
for (j = i ; j < = 5 ; j + +)
{
printf (“ %d ” , j );
}
printf (“\n”);
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 45
BCA I

PROGRAM -43
Write a program to print break function.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
// break function
int i = 1;
clrscr ( );
while ( i < = 10)
{
printf (“%d\n” , i);
if ( i = = 5)
{
break ;
}
// printf (“%d\n” , i);
i++;
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 46
BCA I

PROGRAM -44
Write a program to print continue function.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
// continue function
int i ;
clrscr ( );
for ( i = 1 ; i < = 10 ; i + + )
{
if ( i = = 5)
{
continue ;
}
printf (“%d\n” , i);
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 47
BCA I

PROGRAM -45
Write a program to print factorial function.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n , i , f = 1 ;
clrscr ( );
printf (“Enter factorial value”);
scanf (“%d” , &n);
for (i = 1 ; i < = n ; i + +)
{
f=f*i;
}
printf (“%d” , f );

getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 48
BCA I

PROGRAM -46
Write a program to create a function of addition of 2
numbers with return value.(call by value).

Program:-
#include <stdio.h>
#include <conio.h>
int add ( int , int ) ;
void main ( )
{
int a , b , c ;
printf (“Enter value of a and b”);
scanf (“%d%d” , &a , &b);
c = add ( a , b );
printf (“%d” , c);
getch ( );
}
int add ( int x , int y )
{
int z ;
z=x+y;
return (z);
}
OUTPUT:-

Janak Sahu P a g e | 49
BCA I

PROGRAM -47
Write a program to create a function of addition of 2
numbers without return value.(call by value).

Program:-
#include <stdio.h>
#include <conio.h>
void add ( int , int ) ;
void main ( )
{
int a , b ;
clrscr ( );
printf (“Enter value of a and b”);
scanf (“%d%d” , &a , &b);
add ( a , b );
getch ( );
}
void add ( int x , int y )
{
int z ;
z=x+y;
printf (“%d” , z);
}
OUTPUT:-

Janak Sahu P a g e | 50
BCA I

PROGRAM -48
Write a program to calculate simple interest using
function with return value. (call by value).

Program:-
#include <stdio.h>
#include <conio.h>
int si ( int , int , int ) ;
void main ( )
{
int p , r , t , u ;
printf (“Enter value of p , r , t”);
scanf (“%d%d%d” , &p , &r , &t);
u = si ( p , r , t );
printf (“%d” , u);
getch ( );
}
int si ( int x , int y , int z )
{
int v ;
v = ( x * y * z ) /100 ;
return (v);
}
OUTPUT:-

Janak Sahu P a g e | 51
BCA I

PROGRAM -49
Write a program to calculate simple interest using
function without return value. (call by value).

Program:-
#include <stdio.h>
#include <conio.h>
void si ( int , int , int ) ;
void main ( )
{
int p , r , t ;
printf (“Enter value of p , r , t”);
scanf (“%d%d%d” , &p , &r , &t);
si ( p , r , t );
getch ( );
}
void si ( int x , int y , int z )
{
int u ;
u = ( x * y * z ) /100 ;
printf (“%d” , u);
}
OUTPUT:-

Janak Sahu P a g e | 52
BCA I

PROGRAM -50
Write a program to print factorial number using function
with return value. (call by value).

Program:-
#include <stdio.h>
#include <conio.h>
int fact ( int , int ) ;
void main ( )
{
int x , y , f = 1;
clrscr ( );
printf (“Enter any factorial value \n”);
scanf (“%d” , &x);
f = fact ( x , y);
printf (“%d” , f );
getch ( );
}
int fact ( int n , int i )
{
int f = 1;
for ( i =1; i < = n; i + + )
{
f = f * i;
}
return ( f );
}
OUTPUT:-

Janak Sahu P a g e | 53
BCA I

PROGRAM -51
Write a program to print factorial number using function
without return value. (call by value).

Program:-
#include <stdio.h>
#include <conio.h>
void fact ( int , int ) ;
void main ( )
{
int n , i ;
clrscr ( );
printf (“Enter any factorial value \n”);
scanf (“%d” , &n);
fact ( n , i);
getch ( );
}
void fact ( int n , int i )
{
int f = 1;
for ( i =1; i < = n; i + + )
{
f = f * i;
}
printf (“%d” , f );
}
OUTPUT:-

Janak Sahu P a g e | 54
BCA I

PROGRAM -52
Write a program to swapping using functions.

Program:-
#include <stdio.h>
#include <conio.h>
void swap ( int , int ) ;
void main ( )
{
int a , b ;
printf (“Enter value of a and b\n”);
scanf (“%d%d” , &a , &b);
swap( a , b );
getch ( );
}
void swap ( int x , int y )
{
int z ;
z=x;
x=y;
y=z;
printf (“%d%d” , x ,y );
}
OUTPUT:-

Janak Sahu P a g e | 55
BCA I

PROGRAM -53
Write a program to print power square using pow ( )
function.

Program:-
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main ( )
{
int a , b , p = 1 ;
printf (“Enter a number”);
scanf (“%d” , &a);
printf (“Enter power number”);
scanf (“%d” , &b);
p = pow (a , b);
printf (“%d” , p);
getch ( );
} OUTPUT:-

Janak Sahu P a g e | 56
BCA I

PROGRAM -54
Write a program to calculate power using function with
return value.(call by value).

Program:-
#include<stdio.h>
#include<conio.h>
int power (int , int);
void main()
{
int a , b , c ;
printf(“Enter any number”);
scanf(“%d”,&a);
printf(“Enter power”);
scanf(“%d”,&b);
c = power(a,b);
printf ( “%d” , c );
getch( );
}
int power( int x , int y)
{
int i , p =1;
for ( i=1; i < = y ; i++)
{
p = p*x;
}
return (p);
}
OUTPUT:-

Janak Sahu P a g e | 57
BCA I

PROGRAM -55
Write a program to calculate power using function
without return value. (call by value).

Program:-
#include<stdio.h>
#include<conio.h>
void power (int , int);
void main()
{
int a , b ;
printf(“Enter any number”);
scanf(“%d”,&a);
printf(“Enter power”);
scanf(“%d”,&b);
power (a,b);
getch ( );
}
void power ( int x , int y)
{
int i , p =1;
for ( i=1; i < = y ; i++)
{
p = p*x;
}
printf(“%d”,p);
}
OUTPUT:-

Janak Sahu P a g e | 58
BCA I

PROGRAM -56
Write a program to create a function of addition of 2
numbers with return value.(call by address).

Program:-
#include <stdio.h>
#include <conio.h>
int add ( int , int ) ;
void main ( )
{
int a , b , c ;
printf (“Enter value of a and b”);
scanf (“%d%d” , &a , &b);
c = add ( &a , &b );
printf (“%d” , c);
getch ( );
}
int add ( int x , int y )
{
int z ;
z=x+y;
return (z);
}
OUTPUT:-

Janak Sahu P a g e | 59
BCA I

PROGRAM -57
Write a program to create a function of addition of 2
numbers without return value.(call by address).

Program:-
#include <stdio.h>
#include <conio.h>
void add ( int , int ) ;
void main ( )
{
int a , b ;
printf (“Enter value of a and b”);
scanf (“%d%d” , &a , &b);
add ( &a , &b );
getch ( );
}
void add ( int x , int y )
{
int z ;
z=x+y;
printf (“%d” , z);
}
OUTPUT:-

Janak Sahu P a g e | 60
BCA I

PROGRAM -58
Write a program to calculate simple interest using
function with return value.(call by address).

Program:-
#include <stdio.h>
#include <conio.h>
int si ( int , int , int ) ;
void main ( )
{
int p , r , t , u ;
printf (“Enter value of p , r , t”);
scanf (“%d%d%d” , &p , &r , &t);
u = si ( &p , &r , &t );
printf (“%d” , u);
getch ( );
}
int si ( int x , int y , int z )
{
int v ;
v = ( x * y * z ) /100 ;
return (v);
}
OUTPUT:-

Janak Sahu P a g e | 61
BCA I

PROGRAM -59
Write a program to calculate simple interest using
function without return value.(call by address).

Program:-
#include <stdio.h>
#include <conio.h>
void si ( int , int , int ) ;
void main ( )
{
int p , r , t ;
printf (“Enter value of p , r , t”);
scanf (“%d%d%d” , &p , &r , &t);
si ( &p , &r , &t );
getch ( );
}
void si ( int x , int y , int z )
{
int u ;
u = ( x * y * z ) /100 ;
printf (“%d” , u);
}
OUTPUT:-

Janak Sahu P a g e | 62
BCA I

PROGRAM -60
Write a program to print factorial number using function
with return value. (call by address).

Program:-
#include <stdio.h>
#include <conio.h>
int fact ( int , int ) ;
void main ( )
{
int x , y , f = 1;
clrscr ( );
printf (“Enter any factorial value \n”);
scanf (“%d” , &x);
f = fact ( &x , &y);
printf (“%d” , f );
getch ( );
}
int fact ( int n , int i )
{
int f = 1;
for ( i =1; i < = n; i + + )
{
f = f * i;
}
return ( f );
}

OUTPUT:-

Janak Sahu P a g e | 63
BCA I

PROGRAM -61
Write a program to print factorial number using function
without return value. (call by address).

Program:-
#include <stdio.h>
#include <conio.h>
void fact ( int , int ) ;
void main ( )
{
int n , i ;
clrscr ( );
printf (“Enter any factorial value \n”);
scanf (“%d” , &n);
fact ( &n , &i);
getch ( );
}
void fact ( int n , int i )
{
int f = 1;
for ( i =1; i < = n; i + + )
{
f = f * i;
}
printf (“%d” , f );
}
OUTPUT:-

Janak Sahu P a g e | 64
BCA I

PROGRAM -62
Write a program to calculate power using function with
return value.(call by address).

Program:-
#include<stdio.h>
#include<conio.h>
int power (int , int);
void main()
{
int a , b , c ;
printf(“Enter any number”);
scanf(“%d”,&a);
printf(“Enter power”);
scanf(“%d”,&b);
c = power(&a , &b);
printf ( “%d” , c );
getch( );
}
int power( int x , int y)
{
int i , p =1;
for ( i=1; i < = y ; i++)
{
p = p*x;
}
return (p);
}
OUTPUT:-

Janak Sahu P a g e | 65
BCA I

PROGRAM -63
Write a program to calculate power using function
without return value.(call by address).

Program:-
#include<stdio.h>
#include<conio.h>
void power (int , int);
void main()
{
int a , b ;
printf(“Enter any number”);
scanf(“%d”,&a);
printf(“Enter power”);
scanf(“%d”,&b);
power (&a , &b);
getch ( );
}
void power ( int x , int y)
{
int i , p =1;
for ( i=1; i < = y ; i++)
{
p = p*x;
}
printf(“%d”,p);
}
OUTPUT:-

Janak Sahu P a g e | 66
BCA I

PROGRAM -64
Write a program to calculate factorial using recursion.

Program:-
#include<stdio.h>
#include<conio.h>
int fact (int);
void main ( )
{
int x , y ;
clrscr ( );
printf ("Enter the value");
scanf (“%d” , &x);
y = fact (x);
printf (“%d” , p);
getch ( );
}
int fact (int n)
{
int f;
if (n = = 1)
return(1);
else
f = n*fact(n-1);
return ( f );
}
OUTPUT:-

Janak Sahu P a g e | 67
BCA I

PROGRAM -65
Write a program to take 5 values in an array and print
those five values.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int a [ 5 ] , j , i ;
printf (“Enter five values ”);
for (i = 1 ; i < = 5 ; i + +)
{
scanf ( “%d” , &a [ i ] );
}
for (i = 1 ; i < = 5 ; i + +)
{
printf ( “%d” , a [ i ] );
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 68
BCA I

PROGRAM -66
Write a program to take 10 values in an array and print
value.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int a [ 10 ] , i , s = 0 ;
printf (“Enter 10 values”);
for (i = 1 ; i < = 10 ; i + +)
{
scanf ( “%d” , &a [ i ] );
}
for (i = 1 ; i < = 10 ; i + +)
{
s = a [ i ] + s;
}
printf ( “%d” , s );
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 69
BCA I

PROGRAM -67
Write a program to take 10 element in an array and
search the given number present in an array or not.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int a [ 10 ] , c = 0 , i , b ;
printf (“Enter 10 values\n ”);
for (i = 0 ; i < 10 ; i + +)
{
scanf ( “%d” , &a [ i ] );
}
printf (“Enter any number\n”);
scanf (“%d” , &b);
for (i = 0 ; i < 10 ; i + +)
{
if (a [ i ]= = b)
{
c = 1;
}
}
if ( c = = 1)
printf ( “%d is available” , b);
else
printf (“%d is not available” , b);
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 70
BCA I

PROGRAM -68
Write a program to find maximum number in an array
Of 10 element.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int i , max , a [ 10 ];
printf (“Enter any ten numbers”);
scanf (“%d” , &a);
for (i = 1 ; i < 10 ; i + +)
{
scanf (“%d” , &a [ i ] );
}
max = a [ 1 ];
for (i = 1 ; i < 10 ; i + + )
{
if (max < a [ i ] )
{
max = a [ i ];
}
}
printf ( “max = %d” , max );
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 71
BCA I

PROGRAM -69
Write a program to find minimum number in an array
Of 10 element.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int i , min , a [ 10 ];
printf (“Enter any ten numbers”);
scanf (“%d” , &a);
for (i = 1 ; i < 10 ; i + +)
{
scanf (“%d” , &a [ i ] );
}
min = a [ 1 ];
for (i = 1 ; i < 10 ; i + + )
{
if (min > a [ i ] )
{
min = a [ i ];
}
}
printf ( “min = %d” , min );
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 72
BCA I

PROGRAM -70
Write a program to take 5 element in an array and sort
then in descending order.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int a [ 5 ] , i, j ,t ;
clrscr ( );
printf (“Enter five values”);
for (i = 1 ; i < = 5 ; i + +)
{
scanf (“%d” , &a [ i ] );
}
for (i = 1 ; i < = 5 ; i + +)
{
for ( j = i + 1 ; j < = 5 ; j + +)
{
if (a [ i ] < a [ j ] )
{
t = a [ i ];
a [ i ] = a [ j ];
a [ j ] = t;
}
}
}
for (i = 1 ; i < = 5 ; i + +)
{
printf (“%d\n” , a [ i ] );
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 73
BCA I

PROGRAM -71
Write a program to take 5 element in an array and sort
then in ascending order.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int a [ 5 ] , i, j ,t ;
clrscr ( );
printf (“Enter five values”);
for (i = 1 ; i < = 5 ; i + +)
{
scanf (“%d” , &a [ i ] );
}
for (i = 1 ; i < = 5 ; i + +)
{
for ( j = i + 1 ; j < = 5 ; j + +)
{
if (a [ i ] > a [ j ] )
{
t = a [ i ];
a [ i ] = a [ j ];
a [ j ] = t;
}
}
}
for (i = 1 ; i < = 5 ; i + +)
{
printf (“%d\n” , a [ i ] );
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 74
BCA I

PROGRAM -72
Write a program to multiplication of two matrix.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int a [ 3 ] [ 3 ] , b [ 3 ] [ 3 ] , c [ 3 ] [ 3 ] , i , j , k ;
clrscr ( );
printf (“Enter first matrix”);
for (i = 0 ; i < 3 ; i + +)
{
for (j = 0 ; j < 3 ; j + +)
{
scanf (“%d” , &a [ i ] [ j ] );
}
}
printf (“Enter second matrix”);
for (i = 0 ; i < 3 ; i + +)
{
for (j = 0 ; j < 3 ; j + +)
{
scanf (“%d” , &b [ i ] [ j ] );
}
}
printf (“Multiplication of matrix\n”);
for (i = 0 ; i < 3 ; i + +)
{
for (j = 0 ; j < 3 ; j + +)
{
c [ i ] [ j ] = 0;
}
}
for (i = 0 ; i < 3 ; i + +)
{
for (j = 0 ; j < 3 ; j + +)
{
for (k = 0 ; k < 3 ; k + +)

Janak Sahu P a g e | 75
BCA I

{
c [ i ] [ j ] = c [ i ] [ j ] + a [ i ] [ j ] * b [ k ] [ j ];
}
}
}
for (i = 0 ; i < 3 ; i + +)
{
for (j = 0 ; j < 3 ; j + +)
{
printf (“%d” , c [ i ] [ j ] );
}
printf (“\n”);
}
getch ( );
}

OUTPUT:-

Janak Sahu P a g e | 76
BCA I

PROGRAM -73
Write a program to addition of two matrix.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int a [ 3 ] [ 3 ] , b [ 3 ] [ 3 ] , sum [ 3 ] [ 3 ] , i , j ;
clrscr ( );
printf (“Enter 9 elements for first matrix”);
for (i = 1 ; i < = 3 ; i + +)
{
for (j = 1 ; j < = 3 ; j + +)
{
scanf (“%d” , &a [ i ] [ j ] );
}
}
printf (“Enter 9 elements for second matrix”);
for (i = 1 ; i < = 3 ; i + +)
{
for (j = 1 ; j < = 3 ; j + +)
{
scanf (“%d” , &b [ i ] [ j ] );
}
}
printf (“sum of matrix\n”);
for (i = 1 ; i < = 3 ; i + +)
{
for (j = 1 ; j < = 3 ; j + +)
{
sum [ i ] [ j ] = a [ i ] [ j ] + b [ i ] [ j ] ;
}
}
for (i = 1 ; i < = 3 ; i + +)
{
for (j = 1 ; j < = 3 ; j + +)
{
printf (“%d” , sum [ i ] [ j ] );
}
printf (“\n”);
}
getch ( );
}

Janak Sahu P a g e | 77
BCA I

OUTPUT:-

Janak Sahu P a g e | 78
BCA I

PROGRAM -74
Write a program to subtraction of two matrix.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int a [ 3 ] [ 3 ] , b [ 3 ] [ 3 ] , sub [ 3 ] [ 3 ] , i , j ;
clrscr ( );
printf (“Enter 9 elements for first matrix”);
for (i = 1 ; i < = 3 ; i + +)
{
for (j = 1 ; j < = 3 ; j + +)
{
scanf (“%d” , &a [ i ] [ j ] );
}
}
printf (“Enter 9 elements for second matrix”);
for (i = 1 ; i < = 3 ; i + +)
{
for (j = 1 ; j < = 3 ; j + +)
{
scanf (“%d” , &b [ i ] [ j ] );
}
}
printf (“subtraction of matrix\n”);
for (i = 1 ; i < = 3 ; i + +)
{
for (j = 1 ; j < = 3 ; j + +)
{
sub [ i ] [ j ] = a [ i ] [ j ] - b [ i ] [ j ] ;
}
}
for (i = 1 ; i < = 3 ; i + +)
{
for (j = 1 ; j < = 3 ; j + +)
{
printf (“%d” , sub [ i ] [ j ] );
}
printf (“\n”);
}
getch ( );
}

Janak Sahu P a g e | 79
BCA I

OUTPUT:-

Janak Sahu P a g e | 80
BCA I

PROGRAM -75
Write a program to take 9 elements in an 2 dimensional
array of matrix 3 * 3.

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int a [ 3 ] [ 3 ] , i , j ;
printf (“enter 9 elements”);
for ( i = 0 ; i < = 2 ; i + +)
{
for ( j = 0 ; j < = 2 ; j + +)
{
scanf (“%d” , &a [ i ] [ j ] );
}
}
for ( i = 0 ; i < = 2 ; i + +)
{
for ( j = 0 ; j < = 2 ; j + +)
{
printf (“%d” , a [ i ] [ j ] );
}
printf (“\n”);
}
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 81
BCA I

PROGRAM -76
Write a program to take one string and print that string .

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
char s1 [ 10 ];
clrscr ( );
printf (“Enter any string”);
scanf (“%s” , &s1);
printf (“%s” , s1);
getch ( );
}

OUTPUT:-

Janak Sahu P a g e | 82
BCA I

PROGRAM -77
Write a program to check whether a string is palindrome
or not .

Program:-
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n , r , sum = 0 , temp ;
clrscr ( );
printf (“Enter the number”);
scanf (“%d” , &n);
temp = n ;
while (n>0)
{
r = n % 10 ;
sum = (sum * 10) + r ;
n = n / 10 ;
}
if (temp = = sum)
printf (“Pallindrome number”);
else
printf (“Not palindrome number”);
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 83
BCA I

PROGRAM -78
Write a program to concatenate two string .

Program:-
#include<stdio.h>
#include<conio.h>
void main ( )
{
char s [10] , s2 [10];
int i , l = 0;
clrscr ( );
printf (“Enter first string”);
scanf (“%s” , &s);
printf (“Enter second string”);
scanf (“%s” , &s2);
for (i = 0 ; s [ i ]!='\0' ; i++)
{
l++;
}
for (i = 0 ; s2 [ i ]!='\0' ; i++)
{
s [ l ] = s2 [ i ];
l++;
}
s [ l ] = '\0' ;
printf ("%s" , s);
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 84
BCA I

PROGRAM -79
Write a program to copy one string into another string .

Program:-
#include<stdio.h>
#include<conio.h>
void main ( )
{
char s1 [10] , s2 [10];
int i ;
clrscr ( );
printf (“Enter any string”);
scanf (“%s” , &s1);
for (i = 0 ; s1[ i ]!='\0' ; i++)
{
s2 [ i ] = s1[ i ];
}
s2 [ i ] ='\0';
printf ("%s" , s2);
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 85
BCA I

PROGRAM -80
Write a program to perform pointer arithmetic.

Program:-
#include<stdio.h>
#include<conio.h>
void main()
{
int i = 3 , *x;
float j = 1.5 , *y;
char k = 'c' , *z;
clrscr ( );
printf (“\n%d” , i);
printf (“\n%f ” , j);
printf (“\n%c” , k);
x = &i ;
y = &j ;
z = &k ;
printf (“\naddress of x = %u” , x);
printf (“\naddress of y = %u” , y);
printf (“\naddress of z = %u” , z);
x ++;
y++;
z++;
printf (“\nvalue of x = %u” , x);
printf (“\nvalue of y = %u” , y);
printf (“\nvalue of z = %u” , z);
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 86
BCA I

PROGRAM -81
Write a program to create structure that take roll no. and
name of student.(Structure).

Program:-
#include <stdio.h>
#include <conio.h>
struct student
{
char stname[20];
int stroll;
} s1;
void main()
{
printf(“Enter the student name : “);
gets(s1.stname);
printf(“Enter the roll number of student : “);
scanf(“%d”, &s1.stroll);
printf(“The name of student is %s and roll number is %d “,
s1.stname, s1.stroll);
getch();
}
OUTPUT:-

Janak Sahu P a g e | 87
BCA I

PROGRAM -82
Write a program to create structure that take roll no. and
name of student. (Union).

Program:-
#include <stdio.h>
#include <conio.h>
union student
{
char stname[20];
int stroll;
} s1;
void main()
{
printf("Enter the student name : ");
gets(s1.stname);
printf("The name of student is : %s\n", s1.stname);
printf("Enter the roll number of student : ");
scanf("%d", &s1.stroll);
printf("roll number is : %d \n", s1.stroll);
getch();
}
OUTPUT:-

Janak Sahu P a g e | 88
BCA I

PROGRAM -83
Write a program to demonstrate pointer in array.

Program:-
#include<stdio.h>
#include<conio.h>
void main( )
{
int i = 3;
int *j , **k ;
j = &i ;
k = &j ;
clrscr ( );
printf (“\naddress of i = %u” , &i);
printf (“\naddress of j = %u” , &j);
printf (“\naddress of k = %u", &k);
printf (“\nvalue of i = %d”, i);
printf (“\nvalue of j = %d” , *j);
printf (“\nvalue of k = %d” , **k);
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 89
BCA I

PROGRAM -84
Write a program copy the content of one file into another.
Program:-
#include<stdio.h>

#include<conio.h>
#include<string.h>
void main()
{
FILE *fp1 , *fp2;
char ch , fname1[20] , fname2[20];
clrscr ( );
printf (“enter source file name”);
gets (fname1);
printf (“enter new file name”);
gets (fname2);
fp1= fopen (fname1 , "r");
fp2 = fopen (fname2 , "w");
if (fp1==NULL)
{
printf (“nothing to write”);
}
do
{
ch = fgetc (fp1);
fputc (ch , fp2);
}
while(ch!=EOF);
fcloseall( );
getch ( );
}
OUTPUT:-

Janak Sahu P a g e | 90
BCA I

PROGRAM -85
Write a program to append a content of one file to another
file.
Program:-
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
FILE *fp1 ,*fp2;
char ch , fname1[20] , fname2[20];
clrscr ( );
printf (“enter source file name”);
gets (fname1);
printf (“enter destinatiosn file name”);
gets (fname2);
fp1= fopen(fname1 ,"r");
fp2 = fopen(fname2 ,"a");
if (fp1==NULL)
{
printf (“nothing to write”);
}
do
{
ch= fgetc(fp1);
fputc(ch,fp2);
}
while(ch!=EOF);
fcloseall ( );
getch ( );
}
Output:-

Janak Sahu P a g e | 91

You might also like