0% found this document useful (0 votes)
42 views27 pages

CPGM 1

The document contains a record of programming assignments completed by a student for a core lab course. It includes the student's details and 12 assignments with title, date, program code, input/output and signature. The record is submitted for university examination.

Uploaded by

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

CPGM 1

The document contains a record of programming assignments completed by a student for a core lab course. It includes the student's details and 12 assignments with title, date, program code, input/output and signature. The record is submitted for university examination.

Uploaded by

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

KAMBAN COLLEGE OF ARTS AND SCIENCE

(Co-Education)

Sulthanpet

Department of Computer Science


CORE LAB-I PROGRAMMING LAB: C PROGRAMMING
(For the Academic Year 2022- 2025 -- ODD Semester)

NAME : ....…………………………………………………………………

REGISTER NO: …………………………………………………………………

CLASS : ………………………..……………………………………………

Certified Bonafide record of work done by

…………………………………………………………………………………………

Staff – In – Charge Head of the Department

Submitted for the University Examination held on ………….…………………….

________________ _________________
Internal Examiner External Examiner
Page
S. No. Date Title Sign
No.

1 18-11-22 Standard deviation

2 22-11-22 Prime numbers

Fibonacci series
3 28-11-22

4 1-12-22 Magic square

5 5-12-22 Sorting in ascending order

6 9-12-22 Palindrome

Vowels
7 13-12-22

Factorial
8 16-12-22

Student mark list


9 22-12-22

Matrix addition
10 27-12-22

11 2-1-23 File deletion

12 6-1-23 File copy


1. Standard deviation

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,x[50],i;
float sum=0,mean,va=0,sd;
clrscr();
printf("\t\t\tSTANDARD DEVIATION\t\t\t\n\n");
printf("enter the nmbers of values:");
scanf("%d",&n);
printf("\enter the values:");
for(i=0;i<n;i++)
{
scanf("%d",&x[i]);
sum=sum+x[i];
}
printf("\n\nsum=%f",sum);
mean=sum/n;
printf("\n\nmean=%f",mean);
for(i=0;i<n;i++)
{
va=va+((x[i]-mean)*(x[i]-mean))/n;
}
printf("\n\nvariance=%f",va);
sd=sqrt(va);
printf("\n\nstandard deviation=%f",sd);
getch();
}
1. Standard deviation
Input / output
Enter the number of values: 8
Enter the values: 1
2
5
7
9
6
4
3

Sum=37.000000

Mean=4.625000

Variance=6.234375

Standard deviation=2.496873
3. Fibonacci series

#include<stdio.h>
#include<conio.h>
void main()
{
int a=1,b=-1,fib,count=1,n;
clrscr();
printf("enter the value for n");
scanf("%d",&n);
while(count<=n)
{
fib=a+b;
printf("%d\n",fib);
b=a;
a=fib;
count++;
}
getch();
}
3. Fibonacci series

Enter the value for n: 15

0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
2. Prime numbers

#include<stdio.h>
#include<conio.h>
void main()
{
int n,b=3,i,count=1;
clrscr();
printf("enter the numbers:");
scanf("%d",&n);
while(count<=n)
{
for(i=2;i<=b-1;i++)
{
if(b%i==0)
{
break;
}
}
if(b==i)
{
printf("%d\n",b);
count++;
}
b++;
}
getch();
}
2. Prime numbers

Input
Enter the numbers: 20
Output
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
4. Magic square

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,c,a[50][50];
clrscr();
printf("\n\t\tMAGIC SQURE\n\n");
printf("\enter the size of magic squre:");
scanf("%d",&n);
if(n%2==0)
{
printf("\nmagic squre for %d is not possible",n);
goto end;
}
printf("the magic square for%d*5d is:\n\n",n,n);
j=(n+1)/2;
i=1;
for(c=1;c<=n*n;c++)
{
a[i][j]=c;
if(c%n==0)
{
i=i+1;
goto loop;
}
if(i==1)
i=n;
else
i=i-1;
if(j==n)
j=1;
else
j=j+1;
loop: }
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("%d\t",a[i][j]); }
printf("\n\n");
}
end:
getch();
}
4. Magic square

Input
Enter the size of magic squre:5
The magic square for5*5d is:

17 24 1 8 15

23 5 7 14 16

4 6 13 20 22

10 12 19 21 3

11 18 25 2 9
5. Sorting in ascending order

#include<stdio.h>
#include<conio.h>
void main()
{
int num[100],n,i,j,temp;
clrscr();
printf("\t\t\t**PROGRAM FOR THE GIVEN NUMBERS**");
printf("\n\n ENTER SET NUMBERS:",n);
scanf("%d",&n);
printf("\n\n ENTER %d NUMBERS:",n);
for(i=0;i<n;i++)
{
scanf("%d",&num[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(num[i]>num[j])
{
temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
}
printf("\n\n AFTER SORTING:");
for(i=0;i<n;i++)
{
printf("\n\n%d",num[i]);
}
getch();
}
5. Sorting in ascending order

**PROGRAM FOR THE GIVEN NUMBERS**

ENTER SET NUMBERS: 5

ENTER 5 NUMBERS: 45
12
34
67
56

AFTER SORTING:

12

34

45

56

67
6. Palindrome

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
char a[10],b[10];
clrscr();
printf("\t\t\t PALINDROME \t\t\t\n\n");
printf("enter the string:");
scanf("%s",a);
strcpy(b,a);
strrev(a);
printf("\nthe original string.......%s",b);
printf("\n\n reverse string is.....%s",a);
if(strcmp(b,a)==0)
printf("\n\n the given string is palindrome");
else
printf("\n\n the given string is not palindrome");
getch();
}
6. Palindrome

Input
Enter the string: Malayalam
Output
The original string.......Malayalam

Reverse string is.....Malayalam

The given string is palindrome

PALINDROME
Input
Enter the string: palladam
Output
The original string.......palladam

Reverse string is.....madallap

The given string is not palindrome


7. Vowels

#include<stdio.h>
#include<conio.h>
void main()
{
char str[50];
int i=0,count=0;
clrscr();
printf("\n\t\t\t VOWELS");
printf("\n\t\t\t ******");
printf("\n\n enter the string:");
scanf("%s",str);
while(str[i]!=' ')
{
if(str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o'||
str[i]=='u')
{
count++;
}
i++;
}
printf("\n the given of vowels:%d",count);
getch();
}
7. Vowels

VOWELS
******
Input
Enter the string: i am a good boy
Output
The given of vowels: 6
8. Factorial
#include<stdio.h>
#include<conio.h>
void main()
{
int n,fact(int),t;
clrscr();
printf("\n\t\t\t\tFACTORIAL");
printf("\n\n\t enter the value for n:");
scanf("%d",&n);
t=fact(n);
printf("\n");
printf("\n\t the factorial of given number is :%d",t);
getch();
}
fact(int n)
{
int fact1;
if(n==1)
return(1);
else
fact1=n*fact(n-1);
return(fact1);
}
8. Factorial

FACTORIAL

Input
Enter the value for n:6

Output

The factorial of given number is: 720


9. Student mark list

#include<stdio.h>
#include<conio.h>
struct student
{
int st_no;
char st_name[50];
int sem;
int m1;
int m2;
int m3;
int m4;
int m5;
};
void main()
{
struct student s[100];
int n,i,k;
clrscr();
printf("\n HOW MANY STUDENTS:");
scanf("%d",&n);
for(i=1;i<=n;i++) {
printf("enter student no name semester and 5 subject marks");
scanf("%d%s%d%d%d%d%d
%d",&s[i].st_no,&s[i].st_name,&s[i].sem,&s[i].m1,&s[i].m2,&s[i].m3,&s[i].m4,&s[i].m
5);
}
for(i=1;i<=n;i++)
{ clrscr();
printf("\n\n\t\t\t BHARATHIAR UNIVERSITY");
printf("\n\t\t\t MARK STATEMENT NOV 2014");
printf("\n***********************************************************");
printf("\n\t reg.no:%d\t\t\t\t name:%s",s[i].st_no,s[i].st_name);
printf("\n***********************************************************");
printf("\nsem\t\t\t SUBJECT\t\t\tMARKS");
printf("\n***********************************************************");
printf("\n%d\t\t\t TAMIL\t\t\t\t%d",s[i].sem,s[i].m1);
printf("\n%d\t\t\t ENGLISH\t\t\t%d",s[i].sem,s[i].m2);
printf("\n%d\t\t\t MATHS\t\t\t\t%d",s[i].sem,s[i].m3);
printf("\n%d\t\t\t DIGITAL\t\t\t%d",s[i].sem,s[i].m4);
printf("\n%d\t\t\t C PRO\t\t\t\t%d",s[i].sem,s[i].m5);
printf("\n***********************************************************");
getch();
}
getch();
}
9. Student mark list

***********************************************************

BHARATHIAR UNIVERSITY
MARK STATEMENT NOV 2014
***********************************************************
reg.no:1 name: ajith
***********************************************************
sem SUBJECT MARKS
***********************************************************
1 TAMIL 75
1 ENGLISH 85
1 MATHS 95
1 DIGITAL 90
1 C PRO 80
***********************************************************
10. Matrix addition

#include<stdio.h>
#include<conio.h>
int a[10][10],b[10][10],row,column;
void add(int c[10][10]);
int main()
{
int c[10][10],i,j;
clrscr();
printf("\n\t\t Matrix Addition\n\n");
printf("enter row:");
scanf("%d",&row);
printf("enter column:");
scanf("%d",&column);
printf("enter matrix A:\n");
for (i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
scanf("%d",&a[i][j]);
}}
printf("enter matrix b:\n");
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
scanf("%d",&b[i][j]);
}}
add(c);
printf("\nADDITION\n");
for (i=0;i<row;i++)
{ for(j=0;j<column;j++)
{ printf("\t%d\t",c[i][j]);
}
printf("\n");
}
getch();
return 0;
}
void add(int c[10][10])
{ int i,j;
for(i=0;i<row;i++)
{ for(j=0;j<column;j++)
{ c[i][j]=a[i][j]+b[i][j];
} }\}
10. Matrix addition
Matrix Addition

Enter row:2
Enter column:2
Enter matrix A:
1
2
3
4
Enter matrix b:
5
6
7
8

ADDITION
6 8
10 12
11. File deletion

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<process.h>
void main()
{
int status;
char c1[50],c2[50];
FILE *fp1,*fp2;
clrscr();
fp1=fopen("file01.txt","r");
fp2=fopen("file02.txt","r");
fgets(c1,50,fp1);
fgets(c2,50,fp2);
printf("\n\t\tFILE DELETION\n\n");
if(strcmp(c1,c2)==0)
{
printf("Contents of first file:\n");
printf("%s\n",c1);
printf("Contents of secont file:\n");
printf("%s\n",c2);
printf("Contents are same.\n");
status=remove("file02.txt");
if(status==0)
printf("file02 deleted successfully.\n");
else
printf("file cannot be deleted");
}
else
{
printf("Contents of first file:\n");
printf("%s\n",c1);
printf("Contents of secont file:\n");
printf("%s\n",c2);
printf("Contents are not same,second file cannot be deleted.");
}
getch();
}
11. File deletion

Contents of first file:


1year bsc cs
Contents of secont file:
1 year bsc cs
Contents are not same, second file cannot be deleted.
12. File copy

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
void main()
{
FILE *fp1,*fp2;
char ch;
char c1[500];
int count=0,w=1,i=1;
clrscr();
fp1=fopen("sample1.txt","r");
fp2=fopen("output.txt","w");
fgets(c1,500,fp1);
while(i)
{
ch=fgetc(fp1);
if(ch==EOF)
{
break;
}
else
{
count=count+1;
if(ch==' ')
w=w+1;
if(ch=='\n')
{
i=i+1;
w=w+1;
}
fputc(ch,fp2);
}
}
printf("\n\t\t file copy n\n");
printf("file copied successfully");
printf("\ncontent of file is:\n%s",c1);
printf("\nNumber of charcters in a file:%d",count);
printf("\nNumber of words in a file:%d",w);
printf("\nNumber of lines in a file:%d",i);
fclose(fp1);
fclose(fp2);
getch();
}
12. File copy
File copied successfully
Content of file is:
PLEASE DONT TOUCH
Number of charcters in a file:16
Number of words in a file:3
Number of lines in a file:1

You might also like