Professional Documents
Culture Documents
C Programs Acs - Lab Record
C Programs Acs - Lab Record
PG COLLEGE
(AN AUTONOMOUS COLLEGE)
A COLLEGE WITH POTENTIAL FOR EXCELLENCE ACCREDITED BY NAAC WITH ‘A’ GRADE
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 :
4 Subtraction of two 2
21-6-2018
numbers
5 Division of two numbers 3
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
68 4-8-2018
Program to check a
41
Palindrome or not
69 Program to copy a string 41-42 4-8-2018
92
allocation memory
93 To 54-55 23-8-2018
declare,define,initialization
and accessing the structure
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(“hello world”);
getch();
}
OUTPUT:
“hello world”
#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:
#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
#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
OUTPUT :
enter a and b values
56
8
result is 7
#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
#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
#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
OUTPUT:
enter the height base values
22
3
Area of triangle: 99
#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
#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
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
{
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
#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:
OUTPUT
Number of character: 93
Number of Blanks: 10
Number of Tabs: 0
Number of Lines: 3
#include<stdio.h>
#include<conio.h>
void main()
FILE *f1,*f2,*f3;
int number,i;
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");
while((number=gets(f2))!=EOF)
while((number==gets(f3))!=EOF)
{ n printf("%d",number);
fclose(f1);
fclose(f2);
fclose(f3);
getch();
}
OUTPUT
1 2 3 4 5
2 4
1 3 5
#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