You are on page 1of 74

LOYOLA ACADEMY DEGREE COLLEGE &

PG COLLEGE
(AN AUTONOMOUS COLLEGE)
A COLLEGE WITH POTENTIAL FOR EXCELLENCE ACCREDITED BY NAAC WITH ‘A’ GRADE

(Affiliated to OSMANIA UNIVERSITY)

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING

CERTIFICATE
THIS IS TO CERTIFY THAT THIS IS A BONAFIDE RECORD OF
THE WORK DONE IN PROBLEM SOLVING AND
PROGRAMMING THROUGH C LAB DURING I YEAR I
SEMESTER FOR THE ACADEMIC YEAR 2017-2018.

NAME :
CLASS : ACS
HALL TICKET NUMBER :

INTERNAL EXAMINER PRINCIPAL EXTERNAL EXAMINER


INDEX
NAME OF THE PROGRAM PAGE DATE OF SIGNATURE
SR NO NUMBER SUBMISSITON

1 Hello world program 1 21-6-2018

2 Adding of two numbers 1


21-6-2018

3 Multiply two numbers 2


21-6-2018

4 Subtraction of two 2
21-6-2018
numbers
5 Division of two numbers 3
21-6-2018

6 Program to find simple 3


21-6-2018
interest
7 Program to find area of 4
21-6-2018
circle
8 Program to find area of a 4
21-6-2018
rectangle
9 Program to area of square 5
21-6-2018

10 Program to find 5
28-6-2018
circumference of circle
11 Program to find area of 6 28-6-2018
triangle
12 Program to convert 6
28-6-2018
kilometer/meter
13 Program to convert 7
28-6-2018
temperature to fc
14 Program to obtain gross 7 28-6-2018
salary of an employee with
basic pay,da,hra,md
15 Program to greatest of two 8
28-6-2018
numbers
16 Program to find given 8
28-6-2018
number is positive or
negative
Program to find odd or
17 9 28-6-2018
even number
18 Program to allot grade
9
based on marks obtained 5-7-2018

19 Gross salary by else if


10 5-7-2018
ladder
20 Program to perform 5-7-2018
10-11
arithematic operations
using symbols
21 Program to stimulate
11-12 5-7-2018
calculator using switch
case
22 Program to read
12-13
weekday,weeknumber and 5-7-2018
Print weekday name using
switch case
23 Program to print
13-14 5-7-2018
multiplication table upto
10
24 Program To find natural 13-14 5-7-2018
numbers
25 Program To Check 14
5-7-2018
factorial number or not
26 Program to find reverse 14-15
12-7-2018
number
27 Program to print sum of
15 12-7-2018
digits of a given number
28 Program to check
15-16 12-7-2018
palindrome or not number
29 Program to print
16-17 12-7-2018
Fibonacci series
30 Program to check even 17 12-7-2018
numbers from 2 to 50
31 Program to find prime 17-18 12-7-2018
number or not
32 Program to check leap 18 12-7-2018
year or not
33 Program to print half 18-19 12-7-2018
pyramid using numbers
1
12
123
34 Program to print half 13-7-2018
19
pyramid using
*
**
***
35 Program swapping of two 20 13-7-2018
numbers
36 Program swapping of two 20 13-7-2018
numbers without temp

Program to display and 21 13-7-2018


37
accept a character
38 Program to find greatest of 3 21 13-7-2018
numbers

39 Program to find perfect 22 13-7-2018


square or not

40 Program to find quadratic 22-23 13-7-2018


equation

41 Program to Display array 13-7-2018


23
elements

42 Program to find sum of 23 13-7-2018


Element in the array

43 Program to find smallest 24 13-7-2018


element in array

44 Program to find highest 24-25 20-7-2018


element in array

45 Program To find reverse 25 20-7-2018


order in array

46 Program to find an element in 25-26 20-7-2018


array

47 Program to read and print a 26-27 20-7-2018


2D array

48 Program to find transpose of 27 20-7-2018


a matrix

49 Program to find sum of all 27-28 20-7-2018


the elements in a matrix

50 Program To find sum of 28-29 20-7-2018


matrix

51 Program to print maximum 29-30 20-7-2018


element in array
52 Program to print minimum 30 20-7-2018
element in array

53 Program to find addition of 31 20-7-2018


matrix

54 Program to find product 32-33 20-7-2018


Of matrix

55 Program to find trace of 33-34 27-7-2018


matrix

56 Program to print 34-35 27-7-2018


multiplication table from 1
to 7
57 Program to read and display 35 27-7-2018
1D array

58 Program to print even 35-36 27-7-2018


numbers using arrays

59 Program to print odd 36 27-7-2018


numbers using arrays

60 Program to search an 36-37 27-7-2018


element in array

61 Program to find max and 37-38 27-7-2018


mini number and its
positions using arrays
62 Program To find length of a 38-39 27-7-2018
string

63 Program To convert a string 39 27-7-2018


to lower case

64 Program to convert a string 39 27-7-2018


to upper case

65 Program to print 39-40 27-7-2018


time,date,day
66 Program to print reverse 40 27-7-2018
number using strings

67 Program to convert 2 strings 40 27-7-2018

68 4-8-2018
Program to check a
41
Palindrome or not
69 Program to copy a string 41-42 4-8-2018

70 Program to copy strings

71 Program to print 4-8-2018


42
concatenate of 2 strings
using ( )
72 Program to print 42-43 4-8-2018
concatenate of 2 strings
without using ( )
73 Program to print product of 43
4-8-2018
numbers using functions

74 Program to print sum of 44


4-8-2018
natural numbers

75 Program to print factorial 44 4-8-2018


number
76 Program to print swapping 45 4-8-2018
of 2 numbers using ( )
without temp
77 Program to print swapping 45-46 4-8-2018
of 2 numbers using ( )
78 Program using ( ) with no 46 4-8-2018
argument and no return
type

79 Program using ( )with 46 4-8-2018


argument and no return
type
80 Program using ( )with no 47 14-8-2018
argument and return type

81 Program using ( ) with 47 14-8-2018


argument and return type
82 Call by value 47-48 14-8-2018

83 Call by reference 48-49 14-8-2018

84 Program to print factorial of 49 14-8-2018


a given number using
recursion

85 Program to check the given 49-50 14-8-2018


number is prime or not
using recursion
86 Program to print 1D array 50-51 14-8-2018
elements using ( )

87 Program to check transpose 51 14-8-2018


matrix using ( )

88 Program to find sum using 52 14-8-2018


pointers

89 Program to print pointers to 52 14-8-2018


pointers
90 Program to print 1D array 52-53 23-8-2018
using pointers

Program to pass 1D array to 53 23-8-2018


91
function using pointers

Program to print dynamic 54 23-8-2018

92
allocation memory

93 To 54-55 23-8-2018
declare,define,initialization
and accessing the structure

94 Program to illustrate to copy 55 23-8-2018


one structure to another
structure and also perform
comparison between
structure
95 Program to implement array 56-57 23-8-2018
of structure array within
structure
96 Program to print pointer to 57-58 23-8-2018
structure

97 Program to illustrate 58 23-8-2018


structure containing pointer

98 Passing members of a 58-59 23-8-2018


structure individually

99 Program to find size of 59 7-9-2018


structure and union
100 Program to read a file and 60 7-9-2018
display its content using files

101 Program to count number of 60-61 7-9-2018


space tabs and new lines in a
file

102 Program to handle integer 61-63 7-9-2018


data using file

103 Program to read data from 63 7-9-2018


file

104 Program to copy data from 63 7-9-2018


one FILE to another FILE
C PROGRAMS

1. HELLO WORLD PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(“hello world”);
getch();
}

OUTPUT:

“hello world”

2. ADDING TWO VALUES:

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,result;
printf(“enter a and b values\n”);
scanf(“%d%d”,&a,&b);
result=a+b;
printf(“result is %d”,result);
getch();
}

OUTPUT:

enter a and b values


100
2000
result is 2100
3. MULTIPLY TWO VALUES:

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,result;
printf(“enter a and b values”)’
scanf(“%d%d”,&a,&b);
result=a*b;
printf(“result is %d”,result)’
getch();
}

OUTPUT:
enter a and b values
34
56
result is 1904

4. SUBRACTION OF TWO VALUES:

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b ,result;
printf(“enter a and b values”);
scanf(“%d%d”,&a,&b);
result=a-b;
printf(“result is %d”,result);
getch();
}

OUTPUT:
enter a and b values
1000
101
result is 899

5. DIVISION OF TWO VALUES:


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,result;
printf(“enter a and b values”);
scanf(“%d%d”,&a,&b);
result=a/b;
printf(“result is %d”,result);
getch();
}

OUTPUT :
enter a and b values
56
8
result is 7

6. PROGRAM TO FIND SIMPLE INTEREST:

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int pri,rate,time;
float si;
printf(“enter principal , rate and time values\n”);
scanf(“%d%d%d”,&pri,&rate&time);
si=(pri*time*rate)/100;
printf(“simple interest is %f”,si);
getch();
}

OUTPUT:
enter principal ,rate and time values
25000
10
2
Simple interest is 5000
7. PROGRAM TO FIND AREA OF CIRCLE:

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int r,a;
printf(“enter radius value of circle”);
scanf(“%d”,&r,&a);
a=3.14*r*r;
printf(“area of circle is %d”,a);
getch();
}

OUTPUT:
enter radius value of circle
10
area of circle is 314

8. FIND AREA OF A RECTANGLE:

#include<stdio.h>
#include<conio.h>
void main()
{
int len,ar,ba;
clrscr();
printf(“enter length, base values”);
scanf(“%d%d”,&len&ba);
ar=len*ba;
printf(“area of rectangle\n”);
getch();
}

OUTPUT:
enter length, base values
7
4
area of a rectangle
28
9. PROGRAM TO FIND AREA OF A SQUARE :
#include<stdio.h>
#include<conio.h>
void main()
{
int si,ar;
clrscr();
printf(“enter side value”);
scanf(“%d”,&si);
ar=si*si;
printf(“area of square: %d”,ar);
getch();
}

OUTPUT:
enter side value
12
area of square: 144

10. PROGRAM TO FIND AREA OF CIRCUMFEREMCE OF A CIRCLE:

#include<stdio.h>
#include<conio.h>
void main()
{
int ra,ci;
clrscr();
printf(“enter radius value\n”);
scanf(“%d”,&ra);
ci=2*3.14*r;
printf(“area of circumference of a circle:%d”,ci);
getch();
}

OUTPUT:
enter radius value
24
area of circumference of a circle: 150

11. PROGRAM TO AREA OF TRIANGLE:


#include<stdio.h>
#include<conio.h>
void main()
{
int b,h,a;
clrscr();
printf(“enter the height, base values\n”);
scanf(“%d%d”,&h,&b);
a=1.5*b*h;
printf(“area of triangle: %d”,a);
getch();
}

OUTPUT:
enter the height base values
22
3
Area of triangle: 99

12. PROGRAM TO CONVERT KILOMETER TO METER:

#include<stdio.h>
#include<conio.h>
void main()
{
int km,m;
clrscr();
printf(“enter the distance in km values\n”);
scanf(“%d”,&km);
m=km*1000;
printf(“distance in meters is :%d”,m);
getch();
}

OUTPUT:
enter the distance in km values
2
distance in meters is:2000

13. PROGRAM TO CONVERT TEMPERATURE TO FAHRENHEIT:


#include<stdio.h>
#include<conio.h>
void main()
{
float celsius,fahrenheit;
clrscr();
printf(“enter the temp in Fahrenheit:\n”);
scanf(“%f”,&fahrenheit);
c=5/9*(Fahrenheit-32);
printf(“\n %ffahrenheit=%fcelsius”,fahrenheit,celsius);
getch();
}
OUTPUT:
enter the temp in Fahrenheit:
12
12.00fahrenheit=-11.11celsius

14. PROGRAM TO OBTAIN GROSS SALARY OF AN EMPLOYEE WITH BASIC


PAY,DA,HRA,MD:

#include<stdio,h>
#include<conio.h>
void main()
{
int basic,da,hra,md,tsal,h;
Clrscr();
Printf(“enter the basic pay\n”);
Scanf(“%d”,&basic);
Da=0.10*basic;
Hra=0.20*basic;
Md=0.30*basic;
Tsal=basic+da+md+hra;
Printf(“\n total salary:%d”,tsal);
Getch();
}
OUTPUT:
Enter the basic pay
20000
Total slary:31999

15. PROGRAM TO FIND GREATEST NUMBERS:


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,n3,res;
printf(“enter two nums:”);
scanf(“%d%d”,&a,&b);
if(a>b)
printf(“%d is greater than %d”,a,b);
getch();
}

OUTPUT:
enter two nums:
95
56
95 is greater than 56
16. PROGRAM TO FIND THE GIVEN NUMBER IS POSITIVE OR NEGATIVE :
#include<stdio.h>
#include<conio.h>
void main()
{
float num;
printf(“enter a num:”);
scanf(“%f”,&num);
if(num<0.0)
{
if(num==0.0)
printf(“you entered 0”);
else
printf(“you entered a negative num”);
else
printf(“you entered a positive num”);
getch();
}

OUTPUT:
enter a num:
-34
you entered a negative num

17. PROGRAM TO FIND THE GIVEN NUMBER IS ODD OR EVEN:


#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf(“enter a num”);
scanf(“%d”,&a);
if(a/2==0)
printf(“even num”);
else
printf(“odd num”);
getch();
}
OUTPUT:
enter a num
96
even num

18. PROGRAM TO ALLOT GRADE BASED ON MARKS OBTAINED:


#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c,d,e,f;
clrscr();
printf(“enter marks of 3 subjects\n”);
scanf(“%f%f%f”,&a,&b,&c);
d=a+b+c;
e=d/3;
if(e<=60&&e>=100)
printf(“first division\n”);
else if(e>60&&e<=50)
printf(“second division\n”);
else if (e>=40&&e<=40)
printf(“third division”);
else
printf(“fail….!!!!!!”);
getch();
}
OUTPUT:
enter marks of 3 subjects:
34
45
23
fail…..!!!!!
19. PROGRAM TO FIND SALARY BY ELSE IF LADDER:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,g,h;
clrscr();
printf(“enter the basic pay:”);
scanf(“%d”,&a);
if(a<1500)
{
b=0.10*a;
c=0.90*a;
g=a+b+c;
printf(“\n total salary:%d”,g);
}
else
{
b=500;
c=(a*90)/100;
g=a+b+c;
printf(“total salary is %d”,g);
}
getch();
}
OUTPUT:
enter the basic pay:
23000
total salary is 23229
20. PROGRAM TO PERFORM ARITHMETIC OPERATIONS BY SYMBOLS:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
char ch;
clrscr();
printf(“enter your choice from +,-,*,/,%);
scanf(“%c”,&ch);
printf(“enter 2 nums:”);
scanf(“%d%d”,&a,&b);
if(ch==’+’)
{
c=a+b;
printf(“the sum is %d”,c);
else if(ch==’-‘)
{
c=a-b;
printf(“subtracted :%d”,c);
else if(ch==’*’)
{
c=a*b;
printf(“the multiplied:%d”,c);
}
else if(ch==’/’)
c=a/b;
printf(“division:%d”,c);
else if(ch==’%’)
c=a%b;
printf(“modular division:%d”,c);
else
printf(“wrong operator”);
getch();
}
OUTPUT:
enter your choice from *-+/%
*
enter 2 num:
23 45
the multiplied:1035
21. PROGRAM TO STIMULATE CALCULATOR USING SWITCH CASE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
char op;
clrscr();
printf(“enter your choice from +-*/%\n”);
scanf(“%c”,&op)
printf(“enter 2 nums:”);
scanf(“%d%d”,&a,&b);
switch(op)
{
case ‘+’: printf(“\n %d+%d=%d\n”,a,b,a+b);
break;
case ‘-‘: printf(“\n %d-%d=%d\n”a,b,a-b);
break;
case ‘*’:printf(“\n %d*%d=%d\n”a,b,a*b);
break;
case ‘/’: printf(“\n %d/%d=%d\n”a,b,a/b);
break;
case ‘%’: printf(“\n %d%%d=%d\n”a,b,a%b);
break;
default :printf(“wrong operator…!!!”);
}
getch();
OUTPUT:
enter your choice from *-+/%
8
enter 2 nums:
56 78
56*78=4368
22. PROGRAM TO READ WEEKDAY , WEEK NUMBER AND WEEKDAY NAME
USING SWITCH CASE:
#include<stdio.h>
#include<conio.h>
void main()
{
int day;
clrscr();
printf(“enter a weekday number:”);
scanf(“%d”,&day);
switch(day)
{
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(“wrong…..!!!”);
getch();
}
OUTPUT:
enter weekday number:
6
SATURDAY
23. PROGRAM TO PRINT MULTIPLICATION TABLE UPTO 10:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,I;
printf(“enter a number:\n”);
scanf(“%d”,&n);
printf(“\n”);
for(i=1;i<10;i++)
{
printf(“%d*%d=%d\n”,n,I,n*i);
}
return 0;
getch();
}
OUTPUT:
enter a number:
13
13*1=13
13*2=26
13*3=39
13*4=52
13*5=65
13*6=78
13*7=91
13*8=104
13*9=117
13*10=130
24. PROGRAM TO PRINT SUM OF NATURAL NUMBERS:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,sum=0;
clrscr();
printf(“enter a num”);
scanf(“%d”,&n);
for(i=1;i<=n;++i)
{
while(i<=n)
s=s+i;
i+=1;
}
printf(“sum=%d”,sum);
getch();
}
OUTPUT:
enter a num:
15
sum=120
25. PROGRAM TO CHECK FACTORIAL OF A GIVEN NUMBER:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,f;
f=i=1;
clrscr();
printf(“enter a number:”);
scanf(“%d”,&n);
while(i<=n)
{
f*=i;
i++;
}
printf(“the factorial of %d is:%d”,n,f);
getch();
}
OUTPUT:
enter a number:
5
the factorial of 5 is:120
26. PROGRAM TO FIND REVERSE NUMBER:
#include<stdio.h>
#include<conio.h>
void main()
{
int r,sum=0,n,i;
clrscr();
printf(“enter the number:”);
scanf(“%d”,&n);
while(n>0)
{
r=n%10;
s=(s*10)+r;
n=n/10;
}
printf(“\n reverse =%d”,s);
getch();
}
OUTPUT:
enter the number:
26
reverse=62
27. PROGRAM TO SUM OF DIGITs OF A GIVEN NUMBER:
#include<stdio.h>
#include<conio.h>
void main()
{
int r,s=0,n,i;
clrscr();
printf(“enter a number\n”);
scanf(“%d”,&n);
while(n>0)
{
r=n%10;
s=s+r;
n=n/10;
printf(“sum=%d”,s);
getch();
}
OUTPUT:
enter a number
10
sum=1
28. PROGRAM TO FIND PALINDROME NUMBER:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,s=0,r,nl;
clrscr();
printf(“enter a number\n”);
scanf(“%d”,&n);
nl=n;
while(n!=0)
{
r=n%10;
s=(s*10)+r;
n=n/10;
}
if(nl==s)
printf(“palindrome\n”);
else
printf(“not a palindrome\n”);
getch();
}
OUTPUT:
enter a number
26
not a palindrome
29. PROGRAM TO FIND FIBONACCI SERIES:
#include<stdio.h>
#include<conio.h>
void main()
{
int f1=0,f2=1,f3,n;
clrscr();
printf(“enter the limit\n”);
scanf(“%d”,&n);
printf(“Fibonacci series\n”);
printf(“%d\n”,f1);
printf(“%d\n”,f2);
do
{
f3=f2+f1;
printf(“%d\n”,f3);
f1=f2;
f2=f3;
}
while(f3<=n)
getch();
}
OUTPUT:
enter the limit:
5
Fibonacci series:
0
1
1
2
3
5
8
30. PROGRAM TO FIND EVEN NUMBERS FROM 2 TO 50:
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
printf(“enter the number\n”);
for(i=2;i<=50;i++)
{
if(i/2==0)
printf(“%d\t”,i);
}
getch();
}
OUTPUT:
enter the number
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50
31. PROGRAM TO FIND PRIME NUMBER OR NOT:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,count=o;
clrscr();
printf(“enter the number\n”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
{
count++;
}
}
if(count==2)
{
printf(“%d is a prime number”,n);
}
else
{
printf(“%d is not a prime number”,n);
}
getch();
}
OUTPUT:
enter the number
5
5 is a prime number
32. PROGRAM TO FIND LEAP YEAR:
#include<stdio,h>
#include<conio.h>
void main()
{
int yr;
clrscr();
printf(“enter the year\n”);
scanf(“%d”,&yr);
if(yr/4==0)
{
if(yr/100==0)
{
if(yr/400==0)
printf(“%d is a leap year”,yr);
else
printf(“%d is not a leap year”,yr);
}
else
printf(“%d is a leap year”,yr);
}
else
printf(“%d is not a leap year”,yr);
getch();
}
OUTPUT:
enter the year
2018
not a leap year
33. HALF PYRAMID USING NUMBERS:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,rows;
clrscr();
printf(“enter the num of rows:\n”);
scanf(“%d”,&row);
for(i=1;i<=rows;++i)
{
for(j=1;j<I;++j)
{
printf(“%d”,j);
}
printf(“\n”)
}
getch();
}
OUTPUT:
enter the num of rows:
6
1
12
123
1234
12345
123456
34. PROGRAM TO PRINT A PATTERN:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,rows;
clrscr();
printf(“enter a num of rows\n”);
scanf(“%d”,&rows);
for(i=1;i<rows;++i)
{
for(j=1;j<=I;++j)
{
printf(“*\n”);
}
printf(“\n”);
}
getch();
}
OUTPUT:
enter a num of rows
5
*
**
***
****
*****

35. PROGRAM OF SWAPING OF TWO NUMBERS:


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf(“enter 2 numbers:”);
scanf(“%d%d”,&a,&b);
temp=a;
a=b;
b=temp;
printf(“\n number after swapping is \n%d\n%d”,a,b);
getch();
}
OUTPUT:
enter 2 numbers:
45
56
numbers after swapping is 56
45
36. PROGRAM SWAPPING OF TWO NUMBERS WITHOUT TEMPARAY
VARIABLE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf(“enter 2 numbers”);
scanf(“%d%d”,&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf(“numbers after swapping are\n%d\n%d”,a,b);
getch();
}
OUTPUT:
enter 2 numbers
67
78
numbers after swapping are
78
67
37. PROGRAM TO DISPLAY AND ACCEPT A CHARACTER:
#include<stdio.h>
#include<conio.h>
void main()
{
char a;
clrscr();
printf(“enter character”);
a=getchar();
putchar(a);
getch();
}
OUTPUT:
enter character
4
38. PROGRAM TO FIND GREATEST OF 3 NUMBERS:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf(“enter a,b,c values\n”);
scanf(“%d%d%d”,&a,&b,&c);
if(a>b)
{
if(a>c)
printf(“a is big”);
else
printf(“b is big”);
}
else
{
if(b>c)
printf(“b is big”);
else
printf(“c is big”);
}
getch();
}
OUTPUT:
enter a,b,c values
938
a is big
39. PROGRAM TO FIND PERFECT SQUARE OR NOT:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,r;
clrscr();
printf(“enter the values\n”);
ccanf(“%d”,&n);
r=sqrt(n);
if(r*r==n)
printf(“perfect square”);
else
printf(“not a perfect square”);
getch();
}
OUTPUT:
enter the values
2
not a perfect square
40. PROGRAM TO FIND QUADRATIC EQUATION:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,d,r,s;
clrscr();
printf(“enter the values of a,b,c in a(x*x)+b*+c:”);
scanf(“%d%d%d”,&a,&b,&c);
d=sqrt(b*t-4*a*c);
r=(-b+a)/(2*a);
s=(-b-d)/(2*a);
if(d>0)
printf(“the roots %d%d are real and distinct”);
else if(d==0)
printf(“roots are real and equal”);
getch();
}
OUTPUT:
enter the values of a,b,c
2.3
4
5.6
The roots are real and distinct
41. PROGRAM TO DISPLAY ARRAY ELEMENTS:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,j;
clrscr();
printf(“enter 6 elements in array”);
for(i=0;i<6;i++)
scanf(“%d”,a[j]);
}
for(j=0;j<6;j++)
getch();
}
OUTPUT:
enter 6 elements in array
123456
123456
42. PROGRAM TO FIND SUM OF ARRAY ELEMENTS:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,y,k,sum=0;
clrscr();
printf(“enter 6 elements in array:\n”);
for(i=0;i<6;i++)
{
scanf(“%d”,&a[i]);
sum+=a[i];
}
printf(“sum of the elements is %d”,sum);
getch();
}
OUTPUT:
enter 6 elements in array:
659724
Sum of the elements is 33

43. PROGRAM TO FIND SMALLEST ARRAY ELEMENTS:


#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],l,y,i;
clrscr();
printf(“enter 6 elements in array\n”);
for(i=0;i<6;i++)
{
scanf(“%d”,&a[i]);
l=a[0];
for(y=0;y<6;y++)
{
if(a[y]<l)
l=a[y];}
printf(“the smallest element is %d”,l);
getch();
}
OUTPUT:
enter 6 elements in array
235678
The smallest element is 2
44. PROGRAM TO FIND HIGHEST ARRAY ELEMENTS:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],l,j,i;
clrscr();
printf(“enter 6 elements in array\n”);
for(i=0;i<6;i++)
{
scanf(“%d”,&a[i]);
l=a[0];
for(j=1;j<6;j++)
{
if(a[j]>l)
l=a[j];}
printf(“the highest element is :%d”,l);
getch();
}
OUTPUT:
enter 6 elements in array
135789
The highest element is 9
45. PROGRAM TO FIND REVERSE ORDER ELEMENT:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,c,d,a[100],b[100];
clrscr();
printf(“enter the elements in array\n”);
scanf(“%d”,&n);
printf(“enter the array elements\n”);
for(c=0;c<n;c++)
{
scanf(“%d”,&a[c]);
for(c=n-1;d=0;c>=0;c--,d++)
b[d]=a[c];
for(c=0;c<n;c++)
a[c]=b[c];
printf(“reverse array is\n”);
for(c=0;c<n;c++)
printf(“%d\n”,a[c]);
}
OUTPUT:
enter the number of elements in array
3
enter the array elements
23 56 90
reverse array is 90 56 23
46. PROGRAM FIND AN ELEMENT IN THE ARRAY:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],n,i,c=0;
clrscr();
printf(“enter 5 elements in array\n”);
for(i=0;i<5;i++)
scanf(“%d”,&a[i]);
printf(“enter the number to be searched:\n”);
scanf(“%d”,&n);
for(i=0;i<5;++i)
{
if(n==a[i])
{
c++;
break;
}}
if(c>0)
printf(“number %d found at %dplace”,n,i);
else
printf(“number not found”);
getch();
}
OUTPUT:
enter 5 elements in array
45677
Enter the element to be searched:
8
Number not found
47. PROGRAM TO READ AND PRINT 2D ARRAY:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],i,j,r,c;
clrscr();
printf(“enter the size of rows and col”);
scanf(“%d%d”,&r,&c);
printf(“enter the elements\n”);
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++)
{
printf(“%3d”,a[i][j]);
}
printf(“\n”);
}
getch();
}
OUTPUT:
enter the size of rows and col
23
enter elements
123456
123
456
48. PROGRAM TO FIND TRANPOSE OF MATRIX:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],i,j,r,c;
clrscr();
printf(“enter the size of rows and columns\n”);
scanf(“%d%d”,&r,&c);
printf(“enter the elements\n”);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf(“%d”,&a[i][j]);
printf(“the transpose of the num\n”);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf(“%3d”,a[j][i]);
}
printf(“\n”);
getch();}
OUTPUT:
enter the size of rows and columns
3
3
enter the elements
123
456
789
the transpose of matrix is
147
258
369
49. PROGRAM TO FIND SUM OF ALL THE ELEMENTS IN THE MATRIX:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],i,j,r,c,sum=0;
clrscr();
printf(“enter the size of rows and columns\n”);
scanf(“%d%d”,&r,&c);
printf(“enter the elements\n”);
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++)
sum=sum+a[i][j];
}
printf(“sum of the matrix elements is %d”,sum);
}
getch();
}
OUTPUT:
enter the size of rows and columns
2
2
enter the elements
23
23
sum of matrix elements is 10
50. PROGRAM TO FIND SUM OF MATIX:
#include<stdio.h>
#include<conio.h>
void main()
{
int r,c,a[100][100],b[100][100],sum[100][100],i,j;
printf(“enter num of rows between 1 to 100”);
scanf(“%d”,&r);
printf(“enter num of cols between 1 to 100”);
scanf(“%d”,&c);
printf(“enter the elements of 1st matrix”);
for(i=0;i<r;++i)
for(j=0;j<c;++j)
{
printf(“enter elements a %d%d:”,i+1,j+1);
scanf(“%d”,&a[i][j]);
}
printf(“enter elements of 2nd matrix:\n”);
for(i=0;i<r;++i)
for(j=0;j<c;++j)
{
printf(“enter element a %d%d:”,i+1,j+1);
scanf(“%d”,&b[i][j]);
}
for(i=0;i<r;++i)
for(j=0;j<c;++j)
{
sum[i][j]=a[i][j]+b[i][j];}
printf(“\n sum of two matrix ix \n\n”);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{
printf(“%d”,sum[i][j]);
if(j==c-1)
{
printf(“\n\n”);
}
}
return 0;
}
OUTPUT:
enter number of rows between 1 to 100
2
enter number of columns between 1to 100
3
enter elements of 1st matrix:
234
523
enter elements of 2nd matrix:
-4 5 3
563
sum of two matrix is:
-2 8 7
10 8 6
51. PROGRAM TO FIND MAXIMUM ELEMENT IN THE ARRAY:
#include<stdio.h>
#include<conio.h>
void main()
{
int num[10],i,max=0,n;
printf(“how many elements?\n”);
scanf(“%d”,&n);
printf(“enter %d elements\n”,n);
for(i=0;i<n;i++)
{
scanf(“%d”,&num[i]);
if(num[i]>max)
{
max=num[i];
}}
printf(“max=%d”,max);
getch();
}
OUTPUT:
how many elements?
5
enter 5 elements
45 67 89 100 23
max=100
52. PROGRAM TO FIND MINIMUM ELEMENT USING ARRAYS:
#include<stdio.h>
#include<conio.h>
void main()
{
int num[10],i,n,mini=0;
printf(“how many elements?\n”);
scanf(“%d”,&n);
printf(“enter %d elements\n”);
for(i=0;i<n;i++)
{
scanf(“%d”,&num[i]);
if(num[i]<mini)
{
mini=num[i];
}
}
printf(“mini=%d”,mini);
getch();
}
OUTPUT:
how many elements?
5
enter 5 elements
67
99
12
0
1000
mini=0

53. PROGRAM TO ADD TWO MATRIX:


#include<stdio.h>
#include<conio.h>
void main()
{
int m,n,c,d,f[10][10],s[10][10],sum[10][10];
printf(“enter the number of rows and columns of matrix\n”);
scanf(“%d%d”,&m,&n);
printf(“enter the elements of 1st matrix”);
for(c=0;c<m;c++)
for(d=0;d<n;d++)
scanf(“enter the elements of 2nd matrix”);
for(c=0;c<m;c++)
for(d=0;d<n;d++)
scanf(“%d”,&s[c][d]);
printf(“sum of entered matrix\n”);
for(c=0;c<m;c++)
{
for(d=0;d<n;d++)
{
sum[c][d]=f[c][d]+s[c][d];
printf(“%d\t”,sum[c][d]);
}
printf(“\n”);
return 0;
}
OUTPUT:
enter the number of rows and columns of matrix
2
2
enter the elements of 1st matrix
12
34
enter the elements of 2nd matrix
56
21
sum of entered matrix
68
55

54. PROGRAM TO FIND PRODUCT OF MATRIX:


#include<stdio.h>
#include<conio.h>
void main()
{
int r1,r2,c1,c2,i,j,k;
int a[10][10],b[10][10],c[10][10];
clsrcr();
printf(“enter the order of 1st matrix:\n”);
scanf(“%d%d”,&r1,&c1);
printf(“\n enter the order of 2nd matrix:\n”);
scanf(“%d%d”,&2,&c2);
printf(“enter the elements of 1st matrix:\n”);
for(i=0;i<r1;i++)
{
for(j-0;j<c1;j++)
{
scanf(“%d”,&a[i][j]);
}}
printf(“\n enter the elements of 2nd matrix:”);
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf(“%d”,&b[i][j]);
}}
if(c1==r2)
{
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<r2;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}}
for(i=0;i<r1;i++)
{
printf(“\n”);
for(j=0;j<c1;j++)
{
printf(“%d\t”,c[i][j]);
}}
else
printf(“\n multiplication is not possible”);
getch();
}
OUTPUT:
enter rows and columns of 1 st matrix:
3
3
enter 1st matrix elements:
120
011
201
enter rows and columns of 2nd matrix:
3
3
enter 2nd matrix elements:
112
211
121
product of matrix:
534
332
345
55. TRACE OF MATRIX:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],i,j,r,c,t=0;
printf(“enter rows and columns of the matrix”);
scanf(“%d%d”,&r,&c);
printf(“enter the array elements\n”);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf(“%d”,&[i][j]);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
s=s+a[i][j];
}}
printf(“trace of the matrix is %d”,t);
getch();
}
OUTPUT:
enter the size of rows and columns
2
enter the array elements
12
34
trace of the matrix is 5
56. PROGRAM TO PRINT A MULTIPLICATION TABLE FROM THE NUMBERS 1
TO 7:
#include<stdio.h>
#include<conio.h>
#define COLUMNS 7
#define ROWS 7
void main()
{
int col,row,prd[R][C];
int i,j;
clrscr();
printf(“multiplication table from 1 to 7\n\n”);
printf(“ “):
printf(“_______________”);
printf(“%4d”,j);
printf(“\n”);
printf(“_______________”);
for(i=0;i<R;i++)
{
Row i+1;
for(j=1;j<=C;j++)
{
c=j;
prd[i][j]=row*col;
printf(“%4d”,prd[i][j]);
}
printf(“\n”);
}
getch();
}
OUTPUT:
multiplication table from 1 to 7
1*1=1 2*1=2 3*1=3 4*1=4 5*1=5 6*1=6 7*1=7
1*2=2 2*2=4 3*2=6 4*2=8 5*2=10 6*2=12 7*2=14
1*3=3 2*3=6 3*3=9 4*3=12 5*3=15 6*3=18 7*3=21
1*4=4 2*4=8 3*4=12 4*4=16 5*4=20 6*4=24 7*4=28
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25 6*5=30 7*5=35
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36 7*6=42
1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56
1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63
1*10=10 2*10=20 3*10=30 4*10=40 5*10=50 6*10=60 7*10=70

57. PROGRAM TO READ AND DISPLAY 1D ARRAY:


#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n;
clrscr();
printf(“enter the size of the array\n”);
scanf(“%d”,&n);
printf(“enter elements\n”);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
printf(“the array elements are\n”);
for(i=0;i<n;i++)
printf(“%d\t”,a[j]);
getch();
}
OUTPUT:
enter size of the array
3
enter elements
3
4
5
the array elements are 3 4 5
58. PROGRAM TO PRINT EVEN NUMBERS IN ARRAY:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n;
clrscr();
printf(“enter the size of array\n”);
scanf(“%d”,&n);
printf(“enter elements\n”);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
for(i=0;i<n;i++)
{
if(a[i]%2==0)
printf(“%d is even number”,a[i]);
}
getch();
}
OUTPUT:
enter the size of array
3
enter elements
23
46
89
46 s even number
59. PROGRAM TO PRINT ODD NUMBERS IN ARRAY:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n;
clrscr();
printf(“enter the size of the array\n”);
scanf(“%d”,&n);
printf(“enter elements\n”);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
for(i=0;i<n;i++)
{
if(a[i]%2!=0)
printf(“%d is odd num”,a[i]);
}
getch();
}
OUTPUT:
enter the size of the array
3
enter elements
34
23
94
23 is odd num
60. PROGRAM TO SEARCH AN ELEMENT IN ARRAY:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],ele,num,i;
clrscr();
printf(“enter the elements in array\n”);
scanf(“%d”,&num);
printf(“enter elements”);
for(i=0;i<num;i++)
{
scanf(“%d”,&a[i]);
}
printf(“enter the element to be searched for:”);
scanf(“%d”,&ele);
i=0;
while(i<num&&ele!=a[i])
{
i++;
}
if(i<num)
{
printf(“number found at %d”,i+1);
}
else
{
printf(“number not found”);
}
getch();}
OUTPUT:
enter the elements in array
5
enter elements
11 22 33 44 55
enter the number to searched 44
number found at 3
61. PROGRAM TO FIND MAX AND MINI NUMBER AND ITS POSITIONS:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],n,i,max,min,maxp=0,minp=0;
clrscr();
printf(“enter the size of an array\n”);
scanf(“%d”,&n);
printf(“enter elements\n”);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
max-min=a[0];
for(i=0;i<n;i++)
{
if(a[i]>max)
{
max=a[i];
maxp=I;}
else if(a[i]<min)
{
min=a[i];
minp=I;
}}
printf(“%d is max element at %d position\n”,max,maxp);
printf(“%d is min element at %d position \n”,min,minp);
getch();
}
OUTPUT:
enter the size of an array
3
enter elements
3
1
2
3 is max element at 1
1 is min element at 2
62. PROGRAM TO FIND LENGTH OF THE STRING:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s[10];
int i;
clrscr();
printf(“enter a string\n”);
scanf(“%s”,s);
l=strlen(s);
printf(“length of string is%d”,l);
getch();
}
OUTPUT:
enter a string
Welcome
length of string is 7
63. PROGRAM TO CONVERT A GIVEN STRING TO LOWER CASE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s[10];
clrscr();
printf(“enter a string\n”);
scanf(“%s”,s);
printf(“string lower case is%s”,strlwr(s));
getch();
}
OUTPUT:
enter a string
WELCOME
string lower case is welcome
64. PROGRAM TO CONVERT A GIVEN STRING TO UPPER CASE:
#include<stdio.h>
#include<conio.h>
void main()
{
char s[10];
clrscr();
printf(“enter a string\n”);
scanf(“%s”,s);
printf(“string upper case is %s”,strupr(s));
getch();
}
OUTPUT:
enter a string
Welcome
string upper is WELCOME
65. PROGRAM TO FIND TIME,DATE,DAY:
#include<stdio.h>
#include.h>
#include<time.h>
void main()
{
Time_t tim;
Time(&tim);
clrscr();
printf(“today,date,day,time:%s”,ctime(&tim));
getch();
}
OUTPUT:
today,date,day,time:
thu aug 23
11:10:15 2018
66. PROGRAM TO ISDIGIT:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int x;
clrscr();
x=isdigit(7);
printf(“x is %d”,x);
getch();
}
OUTPUT :
x is 0
67. PROGRAM OF REVERSE A STRING:
#include<stdio.h>
#include<conio.h>
void main()
{
char s[10];
printf(“enter a string\n”);
scanf(“%s”,s);
printf(“reverse string is %s”,strrev(s));
getch();
}
OUTPUT:
enter a string
Welcome
reverse string is emoclew
68. PROGRAM TO CONVERT TWO STRINGS:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[10],s2[10];
printf(“enter string1\n”);
scanf(“%s”,s1);
printf(“enter string2\n”);
scanf(“%s”,s2);
if(strcmp(s1s2)==0)
printf(“both strings are equal\n”);
else
printf(“not equal”);
getch();
}
OUTPUT:
enter string1
Welcome
enter string2
C programming
not equal
69. PROGRAM TO CHECK PALINDROME OR NOT:
#include<stdio.h>
#include<conio.h>
void main()
{
char s1[10],s2[10];
clrscr();
printf(“enter string\n”);
scanf(“%s”,s1);
s2=strrev(s);
if(s1==s2)
printf(“it is a palindrome”);
else
printf(“not a palindrome”);
getch();
}
OUTPUT:
enter string
26
not a palindrome
70. PROGRAM TO COPY A STRING:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int s1[10],s2[10];
clrscr();
printf(“enter a string\n”);
scanf(“%s”,s1);
strcpy(s2,s1);
printf(“original string is %s”,s1);
printf(“copied string is %s”,s2);
getch();
}
OUTPUT:
enter a string
welcome
original string is welcome
copied string is welcome
71. PROGRAM TO CONCATENATE TWO STRINGS USING FUNCTIONS:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[10],s2[10];
clrscr();
printf(“enter a string1\n”);
scanf(%s”,s1);
printf(“enter a string2\n”);
scanf(“%s”,s2);
strcat(s1,s2);
printf(“concatenated string is %s”,s1);
getch();
}
OUTPUT:
enter a string1
C is not object oriented
enter a string2
Language
concatenated string is c is not object oriented language
72. PROGRAM OF CONCATENATE TWO STRINGS WITHOUT USING
FUNCTIONS:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[10],s2[10],s3[10];
int i,j;
clrscr();
printf(“enter a string1\n”);
scanf(“%s”,s1);
printf(“enter a string2\n”);
scanf(“%s”,s2);
for(i=0;s1[i]!=’\0’;i++)
s3[i]=s1[i];
for(j=0;s2[j]!=’\0’;j++)
s3[j]=s2[j];
s3[j]=’\0’;
printf(“concatenated is %s”,s3);
getch();
}
OUTPUT:
enter a string1
C is not object oriented
enter a string2
Language
concatenated is c is not object oriented language
73. PROGRAM TO FIND PRODUCT OF NUMBERS USING FUNCTIONS:
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z;
int nul(int,int);
clrscr();
printf(“enter the values\n”);
scanf(“%d%d”,&x,&y);
p=nul(x,y);
printf(“product is%d”,p);
getch();
}
int nul(int a, int b)
{
int r;
r=a*b;
return r;
}
OUTPUT:
enter the values
2
3
product is 6

74. PROGRAM TO IMPLEMENT SUM OF NATURAL NUMBER USING


FUNCTIONS:
#include<stdio.h>
#include<conio.h>
void main()
{
int sum(int);
int s,n;
clrscr();
printf(“enter value\n”);
scanf(“%d”,&n);
s=sum(n);
printf(“sum of %d is %d”,n,s);
getch();
}
int sum(int n)
{
int i,s1=0;
for(i=1;i<=n;i++)
s1=s1+i;
return s1;
}
OUTPUT:
enter value 3
sum of 3 is 6
75. PROGRAM TO FIND FACTORIAL NUMBER:
#include<stdio.h>
#include<conio.h>
void main()
{
void fact(int);
int s,n;
clrscr();
printf(“enter the values\n”);
scanf(“%d”,n);
fact(n);
getch();
}
void fact(int n)
{
int i,s1=1;
for(i=1;i<=n;i++)
s1=s1*i;
printf(“factorial is %d”,s1);
}
OUTPUT:
enter the value
3
factorial is 6
76. PROGRAM TO SWAP 2 NUMBER USING( ) WITHOUT TEMP:
#include<stdio.h>
#include<conio.h>
void main()
{
void swap(int,int);
int a,b;
clrscr();
printf(“enter two values”);
scanf(“%d%d”,&a,&b);
swap(a,b);
getch();
}
void swap( int a, int b)
{
int a,b;
a=a+b;
b=a-b;
a=a-b;
printf(“swapping Is %d”,a,b);
}
OUTPUT:
enter two values
26
79
swapping is 79 26
77. PROGRAM TO SWAP NUMBERS USING ():
#include<stdio.h>
#include<conio.h>

{
void swap(int,int);
int a,b;
clrscr();
printf(“enter two values\n”);
scanf(“%d%d”,&a,&b);
swap(a,b);
getch();
}
void swap(int a, int b)
{
int a,b,t;
t=a;
a=b;
b=t;
printf(“swapping is %d”,t);
}
OUTPUT:
enter two values
26
79
Swapping 79
26
78. PROGRAM USING ( ) WITH NO ARGUMENTS AND NO RETURN TYPE:
#include<stdio.h>
void display();
void main()
{
display();
getch();
}
void display()
{
printf(“welcome”);
}
OUTPUT:
welcome
79. PROGRAM WITH ARGUMENTS BUT NO RETURN TYPE:
#include<stdio.h>
void display(int);
void main()

{
int a=5;
display(a);
getch();
}
void display(int x)
{
printf(“value is %d”,x);
}
OUTPUT:
value is 5
80. PROGRAM ( )WITH NO ARGUMENT BUT WITH RETURN TYPE:
#include<stdio.h>
int display();
void main()
{
int a;
a=display();
printf(“value is %d”,a);
getch();
}
int display()
{
return 5;
}
OUTPUT:
value is 5
81. PROGRAM WITH ARGUMENT AND WITH RETURN VALUES:
#include<stdio.h>
int sum(int,int);
void main()
{
int a=10,b=20,c;
C=sum(a,b);
Printf(“sum is %d”,c);
getch();
}
int sum(int x,int y)
{
int r;
r=x+y;
return r;
}
OUTPUT:
sum is 30
82. PROGRAM USING CALL BY VALUE:
#include<stdio.h>
#include<conio.h>
void swap(int,int);
void main()
{
int x,y;
clrscr();
printf(“enter x and y values\n”);
scanf(“%d%d”,&x,&y);
swap(x,y);
printf(“in main()x=%d&y=%d”,x,y);
getch();}
void swap(int a,int b)
{
int t;
t=a;
a=b;
b=t;
printf(“in sswap()x=%d&y=%d”,x,y);
}
OUTPUT:
enter x and y values
10
11
In swap() x=11 & y=10
In main()x=10 & y=11
83. PROGRAM USING CALL BY REFERENCE:
#include<stdio.h>
#include<conio.h>
void swap(int *,int *)
void main()
{
int x,y;
clrsscr();
printf(“enter x and y values\n”);
scanf(“%d%d”,&x,&y);
swap(&x,&y);
printf(“in main()x=%d&y=%d”,x,y);
getch();
}
void swap(int *a,int*b)
{
int*t;
*t=*a;
*a=*b;
*b=*t;
printf(“in swap()x=%d&y=%d\n”,*a,*b);
}
OUTPUT:
enter x and y values
10
11
In swap() x=11 & y=10
In main()x=11 & y=10
84. PROGRAM TO IMPLEMENT FACTORIAL NUMBER USING RECURSION():
#include<stdio.h>
#include<conio.h>
int factorial(int);
void main()
{
int n;
clrscr();
printf(“enter a num\n”);
scanf(“%d”,&n);
printf(“factorial of%d is%d”,n,factorial(n));
getch();
}
int factorial(int n)
{
int f;
if(n==0||n==1)
f=1;
else
f=n*factorial(n-1);
return f;
}
OUTPUT:
enter a num
3
factorial of 3 is 6
85. PROGRAM TO CHECK WHETHER A NUMBER IS PRIME OR NOT USING
RECURSION():
#include<stdio.h>
#include<conio.h>
int prime(int x);
{
static int i=2;
if(x%i==0)&&(x!=2)
{
return (1);
}
if(i<x)
{
i++;
prime(x);
}
return 0;
}
void main()
{
int a,l,prime(int);
clrscr();
printf(“enter a num “);
scanf(“%d”,&a);
l=prime(a);
if(l==1)
printf(“%d is not a prime num”);
else
printf(“%d is a prime num”);
getch();
}
OUTPUT:
enter a num 26
26 is a prime num
86. PROGRAM TO PRINT ELEMENTS OF 1D ARRAY USING ():
#include<stdio.h>
#include<conio.h>
void print(int[],int);
void main()
{
int n,a[10],i;
printf(“enter size of the array\n”):
scanf(“%d”,&n);
printf(“enter elements\n”);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
printf(a,n);
getch();
}
void print(int a[],int n)
{
int i;
printf(“the elements are”);
for(i=0;i<n;i++)’
printf(“%d”,a[i]);
}
OUTPUT:
enter size of the array
4
enter elements
27
24
19
16
the elements are
27 24 19 26
87. PROGRAM OF A GIVEN TRANSPOSE MATRIX USING ():
#include<stdio.h>
#include<conio.h>
void transpose(int[][],int,int);
void main()
{
int a[10][10],r,c,i,j;
clrscr();
printf(“enter row & col size\n”);
scanf(“%d%d”,&r,&c);
printf(“enter elements”);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf(“%d”,&a[i][j]);
transpose(a,r,c);
getch();
}
void transpose(int a[][],int r,int c)
{
int i,j;
printf(“transpose of the matrix is:\n”);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
printf(“%d”,&a[j][i]);
Printf(“\n”);
}}
OUTPUT:
enter row & col size
2
2
enter elements
12
34
transpose of the matrix is:
13
24

88. PROGRAM TO FIND SUM USING POINTERS:


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,*p,*p1,s;
clrscr();
printf(“enter values\n”);
scanf(“%d%d”,&I,&j);
P=&I;
p1=&j;
s=*p+*p1;
printf(“sum is %d”,s);
getch();
}
OUTPUT:
enter values
10 20
sum is 30
89. PROGRAM TO PRINT POINTERS TO POINTERS:
#include<stdio.h>
#include<conio.h>
void main()
{
int a=10,*p,**p1;
clrscr();
p=&a;
p1=&p;
printf(“address value is %d *%u”,a,&a);
printf(“using p the values of a is %d”,*p);
Printf(“using p1 the values of a is %d”,**p1);
getch();
}
OUTPUT:
address value is 10 & 12
using p the values of a is 10
using p1 the values of a is 10
90. PROGRAM TO ILLUSTRATE 1D ARRAY USING POINTERS:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n;
clrscr();
printf(“enter array value\n”);
scanf(“%d”,&n);
printf(“enter elments\n”);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
printf(“entered elements are\n”);
for(i=0;i<n;i++)
printf(“%d\t”,*(a+i));
getch();
}
OUTPUT:
enter array value
3
enter elements
234
entered elements are 2 3 4
91. PROGRAM TO PASS 1D ARRAY TO FUNCTION USING POINTERS:
#include<stdio.h>
#include<conio.h>
void display(int*,int);
void main()
{
int a[10],i,n;
clrscr();
printf(“enter size of the array”);
scanf(“%d”,&n);
printf(“enter elements\n”);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
display(a,n);
getch();
}
void display(int *x,int n)
{
int i;
printf(“the entered elements are\n”);
for(i=0;i<n;i++)
Printf(“%d\t”,*(x+i));
}
OUTPUT:
enter size of the array
3
enter elements
23 45 69
the entered elements are 23 45 69
92. PROGRAM TO IMPLEMENT DYNAMIC MEMORY ALLOCATION:
#include<stdio.h>
#include<conio.h>
void main()
{
int *p,n,i;
clrscr();
printf(“enter number of elements\n”);
scanf(“%d”,&n);
P=int *calloc(n,sizeof(int));
printf(“enter elements\n”);
for(i=0;i<n;i++)
scanf(“%d”,p+i);
printf(“the list of elements\n”);
for(i=0;i<n;i++)
printf(“%d\t”,*(p+i);
free(p);
getch();
}
OUTPUT:
enter number of elements
4
enter elements
1234
the list of elements
1234
93. PROGRAM TO DELCARE,DEFINE,INITIALIZATION AND ACCESSING THE
STRUCTURE:
#include<stdio.h>
#include<conio.h>
struct emp
{
int eno;
char name[10];
float sal;
};
void main()
{
clrscr();
struct emp e;
printf(“enter eno,name,sal\n”);
scanf(“%c%s%f”,&eno,&name,&sal);
printf(“the emp info are\n”);
printf(“eno=%d\n name=%s\n sal=%f\n”,eno,name,sal);
}
OUTPUT:
enter eno name sal
1 ram10000
the emp info are
eno=1
name=ram
sal=10000
94. PROGRAM TO ILLUSTRATE COPY ONE STRUCTURE TO ANOTHER
STRUCTURE AND ALSO PERFORM COMPARSION BWTEEN STRUCTURE:
#include<conio.h>
#include<conio.h>
struct book
{
char name[10];
int pages;
float price;
};
void main()
{
struct book b1,b2;
clrscr();
printf(“enter name,pages,price\n”);
scanf(“%s%d%f”,b1.name,&b1.pages,&b1.price);
b2=b1;
printf(“name=%s\npages=%d\nprice=%f”,b2.name,b2.pages,b2.price);
if(b1.name==b2.name)
printf(“books are equal\n”);
else
printf(“books are not equal\n”);
getch();
}
OUTPUT:
enter name pages price
ram 24 100
name=ram
page=24
price=100
books are equal

95. PROGRAM TO IMPLEMENT ARRAY OF STRUCTURE AND ARRAY WITHIN


STRUCTURE:
#include<stdio.h>
#include<conio.h>
struct student
{
int rollno,sub[5];
char name[30];
float per;
};
void main()
{
struct student s[20];
int n,i,j,sum=0;
printf(“how many student details you want to enter\n”);
scanf(“%d\n”,&n);
for(i=0;i<n;i++)
{
printf(“enter student rollno\n”);
scanf(“%d”,&s[i].rollno);
printf(“enter student name\n”);
scanf(“%s”,s[i].name);
printf(“enter 5 subjects marks\n”);
for(j=0;j<5;j++)
{
scanf(“%d”,&s[i].sub[j]);
sum=sum+s[i].sub[j]);
}
s[i]per=sum/5;
}
printf(“student details\n”);
for(i=0;i<n;i++)
{
printf(“rollno=%d\n”,s[i].rollno);
printf(“name=%s”,s[i].name);
printf(“5 subject marks\n”);
for(j=0;j<5;j++)
{
printf(“%d\t”,s[i].sub[j]);
}
printf(“percentage=%f\n”,s[i].per);
}
getch();
}
OUTPUT:
how many student details you want to enter
1
enter student rollno
101
enter student name
Robin
enter 5 subjects marks
25
30
40
19
45
students details
rollno=101
name=robin
5 subject marks
25
30
40
19
45
percentage=159.2
96. PROGRAM TO PRINT POINTER TO STRUCTURE:
#include<stdio.h>
#include<conio.h>
struct emp
{
int empno;
char name[30];
float sal;
};
void main()
{
struct emp e,*ep;
clrscr();
ep=&e;
printf(“enter empno,name,sal\n”);
scanf(“%d%s%f”,&e.empno,e.name,e.sal);
printf(“employee details\n
empno=%d\n
name=%s\n
sal=%f\n,ep->empno,ep->name,ep->sal);
getch();
}
OUTPUT :
enter empno name sal
101
priya
10000
employee details
empno=101
name=priya
sal=10000

97. PROGRAM TO ILLUSTRATE STRUCTURE CONTAINING POINTER:


#include<stdio.h>
#include<conio.h>
struct character
{
char c;
char *p;
};
void main()
{
struct character x;
char ch=’a’;
x.c=ch;
x.cp=&ch;
printf(“value is %c”,x.c);
printf(“address is %u”,x.cp);
getch();
OUTPUT:
value is a
address is 101
98. PASSING MEMEBERS OF A STRUCTURE INDIVIUALLY:
#include<stdio.h>
#include<conio.h>
struct emp
{
int empno;
char name[20];
float sal;
};
void display (int,char[],float)
void main()
{
struct empe;
clrscr();
printf(“enter empno,name,sal\n”);
scanf(“%d%s%f”,&e.name,e.name,&r.sal);
getch();
}
void display(int empno,char name[],flaot sal)
{
printf(“empno=%d\tname=%s\tsal=%f”,e.empno,e.name,e.sal);
}
OUTPUT:
enter empno name sal
111 likitha 10000
empno=111
name=likitha
sal=10000
99. PROGRAM TO FIND SIZE OF STRUCTURE AND UNION :
#include<stdio.h>
#include<conio.h>
struct emp
{
int eno;
char name[30];
float sal;
};
union emp1
{
int eno;
char name[30];
float sal;
};
void main()
{
struct emp e;
union emp1 c1;
printf(“total size of structure %d\n”,sizeof(e));
printf(“total size of union %d\n”,sizeof(c1));
getch();
}
OUTPUT:
total size of structure 36
total size of union 3
100. PROGRAM TO READ A FILE AND DISPLAY ITS CONTENT USING
FILES:

#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *fptr;

char filename[100], c;
clrscr();
printf("Enter the filename to open \n");
scanf("%s", filename);
fptr = fopen(filename, "r");
if (fptr == NULL)
{
printf("Cannot open file \n");
exit(0);
}
c = fgetc(fptr);
while (c != EOF)
{ printf ("%c", c);
c = fgetc(fptr);
}
fclose(fptr);
getch();
}

OUTPUT:

Cannot open file

101. PROGRAM TO COUNT NUMBER OF SPACE TABS AND NEW LINES IN A


FILE:
#include<stdio.h>
#include<conio.h>
void main()
{
FILE*fp;
char ch;
int nol=0,noc=0,nob=0,not=0;
fp=fopen("FILE.TXT","r");
while(1)
{ch=fgetc(fp);
if(ch==EOF)
break;
noc++;
if(ch=="")
nob++;
if(ch=='\n')
nol++;
if(ch=='\t')
not++;
}
fclose(fp);
printf("\n Number of characters: %d",noc);
printf("\n Number of Blancks: %d",nob);
printf("\n Number of Tabs: %d",not);
printf("\n Number of Lines: %d",nol);
getch();
}

OUTPUT

Number of character: 93
Number of Blanks: 10
Number of Tabs: 0
Number of Lines: 3

102. PROGRAM TO HANDLE INTEGER DATA USING FILE:

#include<stdio.h>

#include<conio.h>

void main()

FILE *f1,*f2,*f3;

int number,i;

printf("Content of Data file:\n");

fl=fopen("data","w");

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

scanf("%d",&number);

puts(number,f1);

if(number==1)

break;
}

fclose(f1);

f1=fopen("data","r");

f2=fopen("odd","w");

f3=fopen("even","w");

while((number=gets(f1)!=EOF)

if(number%2==0)

puts(number,f3);

else

puts(number,f2);

fclose(f1);

fclose(f2);

fclose(f3);

f2=fopen("odd","r");

f3=fopen("even","r");

printf("Contents of odd file:\n");

while((number=gets(f2))!=EOF)

{ printf("Content of even file:\n");

while((number==gets(f3))!=EOF)

{ n printf("%d",number);

fclose(f1);

fclose(f2);

fclose(f3);

getch();
}

OUTPUT

Contents of data file:

1 2 3 4 5

Contents of even file:

2 4

Contents of odd file:

1 3 5

103. PROGRAM TO READ DATA FROM FILE:

#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fptr;
char ch;
clrscr();
fptr=fopen(“a.txt”,”r”);
while((ch=fgetc(fptr))!=EOF)
putchar(ch);
fclose(fptr);
getch();
}
OUTPUT:
India
104. PROGRAM TO COPY DATA FROM ONE FILE TO ANOTHER FILE:
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *f1,f2;
char ch;
clrscr();
f1=fopen(“a.txt”,”r”);
f2=fopen(“b.txt”,”w”);
while((ch=fgetc(f1))!=EOF)
fputc(ch,f2);
printf(“copied check in the b.txt”);
fcloseall();
getch();
}
OUTPUT:
Copied check in the b.txt

You might also like