C Programming Final Record - Bca - 5
C Programming Final Record - Bca - 5
PRACTICAL RECORD
C-PROGRAMMING
PAPER CODE:
21UCAP01
NAME: _
REG.NO:
(2021-2022)
SIRI PSG ARTS AND SCIENCE COLLEGE FOR WOMEN
(Affiliated To Periyar University, Salem - 11)
TIRUCHENGODE ROAD, SANKARI-637301
CERTIFICATE
Certified that this is a bonafide record of practical work done by the candidate
Miss/ Mrs. in the computer laboratory during the year
2021 - 2022, Siri PSG Arts and Science College for Women, Sankari.
STAFF
S.NO DATE TITLE PAGE NO
SIGNATURE
CALCULATE THE SUM, AVERAGE
01
AND STANDARD DEVIATION
PRIME NUMBERS UP TO A GIVEN
02
NUMBER
DECIMAL NUMBER INTO BINARY
03
CONVERSION
MULTIPLY TWO MATRICES USING
04
FUNCTIONS
BINOMIAL CO-EFFICIENT USING
05
FUNCTIONS
WHETHER A GIVEN WORD IS A
06
PALINDROME OR NOT
BINARY SEARCH TO FIND NAME
07
IN ALIST OF NAMES
ARRANGE NUMBERS IN
08
ASCENDING ORDER
STUDENTS MARK SHEET USING
09
AN ARRAY OF STRUCTURES
COUNT OF ALPHABETS, SPECIAL
10 CHARACTERS AND WORDS INA
LINE OF TEXT USING FILE
EX.NO:1
CALCULATE THE SUM, AVERAGE AND
DATE: STANDARD DEVIATION
AIM:
To write a C program to find Sum, Average and Standard deviation from a given set of numbers.
ALGORITHM:
#include <stdio.h>
#include<math.h>
#define MAXSIZE 10
void main()
{
float
X[MAXSIZE]; int
i,n;
float avg,var,std,sum=0,sum1=0;
clrscr();
printf(“\n\n\t\t SUM AVERAGE AND STANDARD DEVIATION”);
printf(“\n\n\t\t
***************************”);
printf(“\n\n Enter tha value of n:”);
scanf(“%d”,&n);
printf(“\n\n Enter %d real number\n”,n);
for(i=0;i<n;i++)
{
scanf(“%f”,&X[i]);
}
for(i=0;i<n;i++)
{
sum=sum+X[i];
}
avg=sum/(float)n;
for(i=0;i<n;i++)
{
sum1=sum1+pow((X[i]-avg),2);
}
var=sum1/(float)n;
std=sqrt(var);
printf(“Sum of all elemnts=%2f\n”,sum);
printf(“Average of all elemnts=%2f\n”,avg);
printf(“Standard deviation=%2f\n”,std);
getch();
}
OUTPUT:
RESULT:
Thus the program has been executed successfully and output is verified.
EX.NO: 2
PRIME NUMBERS UP TO A GIVEN NUMBER
DATE:
AIM:
To write a C program to find the prime number from a given list of numbers.
ALGORITHM:
STEP 5: If fact=0 print the number is prime otherwise print the result as not prime.
#include<stdio.h>
void main()
{
int n,i,fact,j;
clrscr();
printf(“Enter the Number”);
scanf(“%d”,&n);
printf(“Prime Numbers are:\n”);
for(i=1;i<=n;i++)
{
fact=0;
for(j=1;j<=n;j++)
{
if(i%j==0)
fact++;
}
if(fact==2)
printf(“%d”,i)
;
}
getch()
OUTPUT:
RESULT:
Thus the program has been executed successfully and output is verified.
EX.NO: 3
DECIMAL NUMBER, INTO BINARY CONVERSION
DATE:
AIM:
To write a C program to convert decimal to binary numbers using while statement.
ALGORITHM:
STEP 4: Use the statement ‘binary number[i++]=quotient %2’ to store the remaining value as
binary number.
#include<stdio.h>
#include<conio.h>
void main()
{
long int decimal number,remainder,quotient; int
binary Number[100],i=1,j;
clrscr();
printf(“\t\t\t TO CONVERT DECIMAL TO BINARY\n”);
printf(“\t\t\t
*********************************************”);
printf(“\n Enter any decimal number:\n”);
scanf(“%1d”,&decimal number);
quotient=decimal number;
while(quotient!=0)
{
binaryNumber[i++]=quotient % 2;
quotient = quotient / 2;
}
printf(“\nEquivalent binary value of decimal number %d:”,decimalnumber);
for(i-1;j>0;j--)
printf(“%d”,binaryNumber[j]);
getch();
}
OUTPUT:
RESULT:
Thus the program has been executed successfully and output is verified.
EX.NO: 4
MULTIPLY TWO MATRICES USING FUNCTIONS
DATE:
AIM:
ALGORITHM:
multiplications.
#include<stdio.h>
#include<conio.h>
void read_arr(int a[10][10],int row,int col)
{
int i,j;
clrscr();
for(i=1;i<=row;i++)
{
for(j=1;j<=col;j++)
{
printf(“Enter Element %d %d : “,i,j);
scanf(“%d”,&a[i][j]);
}
}
}
void mul_arr(int m1[10][10],int m2[10][10],int m3[10[10],int row,int col)
{
int i,j,k;
for(i=1;i<=row;i++)
{
for(j=1;j<=col;j++)
{
for(k=1;k<=row;k++)
{
m3[i][j]=m3[i][j]+(m1[i][k]*m2[k][j]);
}
}
}
}
void print_arr(int m[10][10],int row,int col)
{
int i,j;
for(i=1;i<=row;i++)
{
for(j=1;j<=col;j++)
{
printf(“%d”,m[i][j]);
}
printf(“\n”);
}
void main()
{
int m1[10][10],m2[10][10],m3[10][10],row,col;
clrscr();
printf(“Enter number of rows :”);
scanf(“%d”,&row);
printf(“Enter number of columns :”);
scanf(“%d”,&col);
read_arr(m1,row,col);
read_arr(m2,row,col);
mul_arr(m1,m2,m3,row,col);
printf_arr(m3,row,col);
getch();
}
OUTPUT:
17 20
41 48
RESULT:
Thus the program has been executed successfully and output verified
EX.NO: 5
BIONOMIAL CO-EFFICIENT USING FUNCTIONS
DATE:
AIM:
ALGORITHM:
r.
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int n,r,ncr;
clrscr();
printf(“\n Enter n and r:”);
scanf(“%d%d”,&n,&r);
ncr=fact(n)/(fact(n-r)*fact(r));
printf(“\n Binomial co-efficient : %d”,ncr);
getch();
}
int fact(int x)
{
if(x==0)
return 1;
else
return(x*fact(x-1));
}
OUTPUT:
RESULT:
Thus the program has been executed successfully and output is verified.
EX.NO: 06
WHETHER A GIVEN WORD IS A PALINDROME OR NOT
DATE:
AIM:
ALGORITHM:
#include <stdio.h>
#include<string.h>
void main()
{
char a[100],b[100];
clrscr();
strcpy(b,a);
strrev(b);
if(strcmp(a,b) = = 0)
printf(“Entered string is a palindrome.\n”);
else
printf(“Entered string is not a palindrome.\n”);
getch();
}
OUTPUT:
palindrome: Malayalam
RESULT:
Thus the program has been executed successfully and output is verified.
EX.NO: 7
BINARY SEARCH TO FIND NAME IN A LIST OF NAMES
DATE:
AIM:
To write a C program to find a particular name in a list of names by using Binary Search.
ALGORITHM:
order.
STEP 4: Search the position of the name in the list using strcmp function.
#include<stdio.h>
#include<string.h>
void main()
{
int i,n,low,high,mid;
char a[50][50],key[20];
clrscr();
printf(“Enter the number of names to be added\n”);
scanf(“%d”,&n);
printf(“Enter the name in ascending order\n”);
for(i=0;i<n-1;i++)
{
scanf(%s”,&a[i]);
}
printf(“\n”);
printf(“Enter the name to be searched\n”);
scanf(“%s”,&key);
low=0;
high=n-1;
while(low<=high)
{
mid=(low+high)/2;
if(strcmp(key,a[mid])==0)
{
printf(“key found at the position %d\n”,mid+1);
getch();
exit(0);
}
else if(strcmp(key,a[mid])>0)
{
high=high;
low=mid+1;
}
else
{
low=low;
high=mid-1;
}
}
printf(“name not found\n”);
}
OUTPUT:
Gokila priya
Devika
Bharathi
searched Devika
RESULT:
Thus the program has been executed successfully and output is verified.
EX.NO: 8
ARRANGE NUMBERS IN ASCENDING ORDER
DATE:
AIM:
ALGORITHM:
STEP 4: Compare each element with each other for arrange the number in ascending order.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a,n,number[30];
clrscr();
printf(“\t\t SORTING THE LIST OF GIVEN NUMBERS \n”);
printf(“\t\t
***************************************************\
n”); printf(“Enter the value of N:”);
scanf(“%d”,&n);
printf(“\n Enter the %d numbers:\n”,n);
for(i=0;i<n;++i)
scanf(“%d”,&number[i]);
for(i=0;i<n;++i)
{
for(j=i+1;j<n;++j)
{
if(number[i]>number[j])
{
a=number[i];
number[i]=number[j];
number[j]=a;
}
}
}
printf(“The numbers are arranged in ascending order:\n”);
for(i=0;i<n;++i)
printf(“%d\n”,number[i]);
getch();
}
OUTPUT:
7
3
5
2
8
2
3
5
7
8
RESULT:
Thus the program has been executed successfully and output is verified.
EX.NO: 9
STUDENT’S MARK SHEET USING AN ARRAY OF
DATE: STRUCTURES
AIM:
ALGORITHM:
required fields.
STEP 4: Calculate total, average, secured class and status form the values.
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct mark_sheet
{
char name[20];
long int rollno;
int marks[10];
int total;
float average;
char rem[10];
char c1[20];
}
students[100];
void main()
{
int a,b,n,flag=1;
char ch; clrscr();
printf(“How many students : \n”);
scanf(“%d”,&n); for(a=1;a<=n;+
+a)
{
printf(“\n\n Enter the details of %d students :”, n-a+1);
printf(“\n\n Enter student %d Name : “,a);
scanf(“%s”,students[a].name);
printf(“\n\n Enter student %d Roll Number :”,a);
scanf(“%1d”,&students[a].rollno);
students[a].total=0;
printf(“\n Enter the class of the students:”);
scanf(“%s”,students[a].c1); for(b=1;b<=5;+
+b)
{
printf(“\n\n Enter the mark of subject-%d :”,b);
scanf(“%d”,&students[a].marks[b]);
students[a].total+=students[a].marks[b];
if(students[a].marks[b]<40)
flag=0;
}
students[a].average=students[a].total/n;
if(flag==1)
strcpy(students[a].rem, “pass”);
else
strcpy(students[a].rem, “Fail”);
flag=1;
}
for(a=0;a<=n;++a)
{
clrscr();
printf(“\n\n\t\t\t\t Mark Sheet\n”);
printf(“\n Name of Student:%s”, students[a].name);
printf(“\t\t\t\t Roll No: %1d”, students[a].rollno); printf(“\n
“)
; for(b=1;b<=5;b++)
{
printf(“\n\n\t Subject %d \t\t :\t%d”,b,students[a].marks[b]);
}
printf(“\n\n \
n”); printf(“\n\n Total Marks : %d”, students[a].total); printf(“\t\
t\t\t Average Marks : %5.2f”, students[a].average); printf(“\n\n
Class : %s”, students[a].c1);
printf(“\t\t\t\t Status : %s”, students[a].rem);
printf(“\n\n\n\t\t\t\t Press Y for continue…”);
ch=getchar();
if((ch==’y’)||(ch==’Y’))
continue;
}
getch()
}
OUTPUT:
RESULT:
Thus the program has been executed successfully and output is verified.
EX.NO: 10
COUNT OF ALPHAPETS, SPECIAL
DATE: CHARCTERS AND WORDS IN A LINE OF
TEXT USING FILE
AIM:
To Write a C program to find the number of alphabets, special characters and word using
file.
ALGORITHM:
text.
STEP 9: If it is value then check anyone of digits then increment the variables digits.
STEP 10: If it is text the check anyone of special character and increment it.
STEP 11: If it is text the check anyone of word and increment the variable word.
#include<stdio.h>
void main()
{
FILE*p;
char ch;
int w=1;
int chh=0;
int no=0;
int sy=0;
clrscr();
p=fopen(“file.txt”,
“r”); if(p==NULL)
{
printf(“file not found”);
}
else
{
ch=fgetc(p);
while(ch!=EOF)
{
printf(“%c”,ch);
if(ch==’ ‘||ch==’\
n’)
{
w++;
}
if(ch>=’0’&&ch<=’9’
) no++;
else if(ch>=’a’&&ch<=’z’)
chh++;
else sy++;
ch=fgetc(p);
}
printf(“\n Words in a file are=%d”,w);
printf(“\n no of char=%d”,chh);
printf(“\n no of numbers=%d”,no);
printf(“\n no of sybols=%d”,sy);
}
fclose(p);
getch();
}
OUTPUT:
=4 No of chars =12
No of
numbers=1 No
of symbols=5
RESULT:
Thus the program has been executed successfully and output is verified.