Professional Documents
Culture Documents
CS8261
C PROGRAMMING LAB MANUAL
NAME ………………
REGISTER NO ………………
DEPARTMENT ………………
YEAR ………………
DEPARTMENT OF SCIENCE AND HUMANITIES – CSE - II - SEMESTER Page 1
4213 – KCET CS8261-C PROGRAMMING LAB MANUAL R-2017
CS8261
C PROGRAMMING LAB MANUAL
EXPERIMENTS
PAGE
S.NO DATE PARTICULARS MARK SIGN
NO
PHASE - I
1. FACTORIAL
2. AREA OF CIRCLE
3. FIBONACCI SERIES
4. LEAP YEAR
5. ARMSTRONG NUMBER
6. SUM OF DIGITS
7. QUADRATIC EQUATION
8. PRIME NUMBER
13. PALINDROME
14. CALCULATOR
PHASE - II
21. MIN AND MAX NUMBER IN AN ARRAY
PAGE
S.NO DATE PARTICULARS MARK SIGN
NO
26. MATRIX SUBTRACTION
27. TRANSPOSE MATRIX
REVERSE STRING WITHOUT CHANGING
28.
POSITION
29. FINDING TOTAL NUMBER OF WORDS
30. CAPITALIZE THE FIRST WORD
31. REPLACE A WORD WITH ANOTHER WORD
32. SORTING USING PASS BY REFERENCE
33. SWAPING USING PASS BY REFERENCE
34. STRING OPERATIONS
35. SORTING NAMES
36. LOWER CASE TO UPPER CASE
37. DIFFERENCE BETWEEN MAX AND MIN NO.
38. ACCEPT A NUMBER AND PRINT IN WORDS
39. SUBJECT AVERAGE USING UNION
40. STRING CONCATENATION
PHASE - III
41. FINDING INTERNAL MARK OF A STUDENT
STUDENT DATABASE USING RANDOM
42.
ACCESS FILE
43. PAYROLL PROCESSING
44. TELEPHONE DIRECTORY
45. RAILWAY RESERVATION
COMPLETED/NOT COMPLETED
AIM:
ALGORITHM:
STEP 1: Start
STEP 2: Read n
STEP 3: Initialize fact=1
STEP 4: for i=1;i<=num;i++
STEP 5: Calculate fact =fact * i
STEP 6: Print fact
STEP 7: Stop
PROGRAM:
#include<stdio.h>
void main()
{
int fact=1,i,num;
printf("Enter the number: ");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
fact=fact*i;
}
printf("The factorial of %d is: %d",num, fact);
getch();
}
OUTPUT:
OBS
REC
VIVA
TOTAL
RESULT:
AIM:
ALGORITHM:
STEP 1: Start
STEP 2: Read Radius
STEP 3: Area -> PI * Radius * Radius, PI=3.14
STEP 4: Per,-> 2*PI * Radius
STEP 5: Print area prem
STEP 6: Stop
PROGRAM:
#include<stdio.h>
#define PI 3.14
int main()
{
float rad,area,perm;
printf(“Enter radius of circle: ”);
scanf(“%f”,&rad);
area=PI*rad*rad;
perm=2*PI*rad;
printf(“Area of circle: %f \n Perimeter of circle: %f\n”,area,perm);
return 0;
}
OUTPUT:
Enter radius of circle: 2.34
OBS
REC
VIVA
TOTAL
RESULT:
AIM:
ALGORITHM:
STEP 1: Start
STEP 2: Read n
STEP 3: Initialize fib=0,a=0,and b=1
STEP 4: for i=1;i<num;i++
STEP 5: Calculate fib=fib+a
STEP 6: Assign a=b and b=fib
STEP 7: Print fib
STEP 8: Stop
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int num,fib=0,a=0,b=1,i;
clrscr();
printf("Enter the Range: ");
scanf("%d",&num);
printf("FIBBONACI SERIES\n");
if(num==0)
printf("0");
else
{
for(i=0;i<num;i++)
{
fib=fib+a;
a=b;b=fib;
printf("%d\t",fib);
getch();
}
}
}
OUTPUT:
FIBBONACI SERIES
0 1 1 2 3 5 8 13 21 34
OBS
REC
VIVA
TOTAL
RESULT:
AIM:
ALGORITHM:
STEP 1: Start
STEP 2: Read year
STEP 3: if year %4 == 0 and year %100 !=0 or year%400 ==0
STEP 4: Print the given year is leap year
STEP 5: else
STEP 6: Print the given year is not a leap year
STEP 7: Stop
PROGRAM:
#include <stdio.h>
#include <conio.h>
void main()
{
int year;
clrscr();
printf("Enter the Year (YYYY) : ");
scanf("%d",&year);
if(year%4==0 && year%100!=0 || year%400==0)
printf("\nThe Given year %d is a Leap Year");
else
printf("\nThe Given year %d is Not a Leap Year");
getch();
}
OUTPUT: 1
OUTPUT: 2
OBS
REC
VIVA
TOTAL
RESULT:
AIM:
ALGORITHM:
STEP 1: Start
STEP 2: Initialize the set of values
STEP 3: Read the value n and assign it to temp variable
STEP 4: perform rem=temp%10
Num=num+(rem*rem*rem)
Temp=temp/10
STEP 5: if num==n Print the number is Armstrong
Else
Print the number is not Armstrong
STEP 6: Stop
PROGRAM
#include <stdio.h>
#include <conio.h>
void main()
{
int n, n1, rem, num=0; clrscr();
printf("\n ARMSTRONG NUMBER");
printf("Enter a positive integer: ");
scanf("%d", &n);
n1=n;
while(n1!=0)
{
rem=n1%10;
num=num+(rem*rem*rem);
n1=n1/10;
}
if(num==n)
printf("%d is an Armstrong number",n);
else
printf("%d is not an Armstrong number",n);
getch();
}
OUTPUT: 1
ARMSTRONG NUMBER
Enter a positive integer: 371
371 is an Armstrong number
OUTPUT: 2
OBS
ARMSTRONG NUMBER
Enter a positive integer: 125 REC
125 is not an Armstrong number
VIVA
TOTAL
RESULT:
SUM OF DIGITS
#include <stdio.h>
int main()
{
int n, t, sum = 0, remainder;
printf("Enter an integer\n");
scanf("%d", &n);
t = n;
while (t != 0)
{
remainder = t % 10;
sum = sum + remainder;
t = t / 10;
}
return 0;
}
QUADRATIC EQUATION
#include <stdio.h>
#include <math.h>
int main()
{
int a, b, c, d;
double root1, root2;
printf("Enter a, b and c where a*x*x + b*x + c = 0\n");
scanf("%d%d%d", &a, &b, &c);
d = b*b - 4*a*c;
if (d < 0) { //complex roots
printf("First root = %.2lf + j%.2lf\n", -b/(double)(2*a), sqrt(-d)/(2*a));
printf("Second root = %.2lf - j%.2lf\n", -b/(double)(2*a), sqrt(-d)/(2*a));
}
else { //real roots
root1 = (-b + sqrt(d))/(2*a);
root2 = (-b - sqrt(d))/(2*a);
PRIME NUMBER
#include <stdio.h>
int main()
{
int n, i, flag = 0;
if (n == 1)
{
printf("1 is neither a prime nor a composite number.");
}
else
{
if (flag == 0)
printf("%d is a prime number.", n);
else
printf("%d is not a prime number.", n);
}
return 0;
}
{
int n, i, sum = 0;
printf("Sum = %d",sum);
return 0;
}
getch();
}
MAXIMUM OF 3 NUMBER
#include <stdio.h>
int main()
{
return 0;
}
ODD OR EVEN
#include <stdio.h>
int main()
{
int number;
return 0;
}
PALINDROME
#include <stdio.h>
int main()
{
int n, reversedInteger = 0, remainder, originalInteger;
originalInteger = n;
return 0;
}
AIM:
ALGORITHM:
STEP 1: Start
STEP 2: Read first and second number
STEP 3: switch choice
STEP 4: if Choice==1 perform addition
STEP 5: Choice ==2 perform subtraction
Choice==3 perform multiplication
Choice==4 perform division
Choice==5 perform square
STEP 6: Print result
STEP 7: Stop
PROGRAM:
#include <stdio.h>
#include <conio.h>
void main()
{
int fn,sn,c,result,sq1,sq2;
float r;
char c1;
clrscr();
printf("Enter the First Number : ");
scanf("%d",&fn);
printf("\nEnter the Second Number : ");
scanf("%d",&sn);
{
printf("\nWhich operations you want to perform (+,-,*,/,s)\n");
c=getch();
switch(c)
{
case '+':
{
result = fn+sn;
printf("Sum is %d\n",result);
break;
}
case '-':
{
result = fn-sn;
printf("Difference is %d\n",result);
break;
}
case '*':
{
result = fn*sn;
printf("Multiplication %d\n",result);
break;
}
case '/':
{
result = fn/(float)sn;
printf("Division is %.2f\n",result);
break;
}
case 's':
{
sq1=fn*fn;
printf("First number square is: %d\n",sq1);
sq2 = sn*sn;
printf("Second number square is: %d\n",sq2);
break;
}
}
}
}
OUTPUT
-
Difference is 5
Which operations you want to perform (+,-,*,/,s)
*
Multiplication 50
Which operations you want to perform (+,-,*,/,s)
/
Division is 2.00
Which operations you want to perform (+,-,*,/,s)
s
AIM:
In the given set of numbers find the numbers which are perfect cube or number with multiples
of 4 and divisible by 6 or a prime number.
ALGORITHM:
STEP 1: Start
STEP 2: Initialize the array as nArray[] and wArray[]
STEP 3: Check for perfect cube if i*i*i==num
STEP 4: Check for prime if num%i==0
STEP 5: Check for multiples of 4 and divisible by 6
if(nArray[i]%4==0 && nArray[i]%6==0)
STEP 6: Stop
PROGRAM:
#include <stdio.h>
#include <math.h>
void main()
{
int nArray[50],wArray[50],nelem,sq,i,j,t;
clrscr();
printf("\nEnter the number of elements in an array: ");
scanf("%d",&nelem);
printf("\nEnter %d elements: \n",nelem);
for(i=0;i<nelem;i++)
scanf("%d",&nArray[i]);
// SORTING AN ARRAY
for(i=0;i<nelem;i++)
for(j=i+1;j<nelem;j++)
if(nArray[i] > nArray[j])
{
t = nArray[i];
nArray[i] = nArray[j];
nArray[j] = t;
}
//CALCULATE THE WEIGHT
for(i=0; i<nelem; i++)
{
wArray[i] = 0;
if(percube(nArray[i]))
wArray[i] = wArray[i] + 5;
if(nArray[i]%4==0 && nArray[i]%6==0)
DEPARTMENT OF SCIENCE AND HUMANITIES – CSE - II - SEMESTER Page 24
4213 – KCET CS8261-C PROGRAMMING LAB MANUAL R-2017
wArray[i] = wArray[i] + 4;
if(prime(nArray[i]))
wArray[i] = wArray[i] + 3;
}
for(i=0; i<nelem; i++)
printf("<%d,%d>", nArray[i],wArray[i]);
getch();
}
//CALCULATING PRIME NUMBER
int prime(int num)
{
int flag=1,i;
for(i=2;i<=num/2;i++)
if(num%i==0)
{
flag=0;
break;
}
return flag;
}
//CALCULATING PERFECT CUBE
int percube(int num)
{
int i,flag=0;
for(i=2;i<=num/2;i++)
if((i*i*i)==num)
{
flag=1;
break;
}
return flag;
}
OUTPUT:
OBS
REC
VIVA
TOTAL
RESULT:
AIM:
ALGORITHM:
STEP 1: Start
STEP 2: Initialize sum=0,count=0,height[100]
STEP 3: for i=0 ;i<=n;i++
STEP 4: sum=sum+height[i]
STEP 5: if(height[i]>avg
Then print the number of persons above average
STEP 6: Stop
PROGRAM
#include <stdio.h>
#include <conio.h>
void main()
{
int i,n,sum=0,count=0,height[100];
float avg;
clrscr();
printf("Enter the Number of Persons : ");
scanf("%d",&n);
printf("\nEnter the Height of each person in centimeter: \n");
for(i=0;i<n;i++)
{
scanf("%d",&height[i]);
sum = sum + height[i];
}
avg = (float)sum/n;
for(i=0;i<n;i++)
if(height[i]>avg)
count++;
printf("\nAverage Height of %d persons is : %.2f\n",n,avg);
printf("\nThe number of persons above average : %d ",count);
getch();
}
OUTPUT:
OBS
REC
VIVA
RESULT:
AIM:
ALGORITHM:
STEP 1: Start
STEP 2: Read weight and height
STEP 3: bmi=w/(h*h)
STEP 4: If bmi<18.5
STEP 5: print Underweight
STEP 6: Stop
PROGRAM
#include<stdio.h>;
void main()
{
float w,h,bmi;
printf("Enter weight in kgs and height in meters: ");
scanf("%f%f",&w,&h);
bmi=w/(h*h);
printf("bmi: %f",bmi);
bmi<18.5?printf("Underweight"):(bmi<25)?printf("Normal weight"):(bmi<30)?
printf("Overweight"):printf("Obesity");
}
OUTPUT
Bmi:1.752066 Underweight
OBS
REC
VIVA
TOTAL
RESULT
AIM:
ALGORITHM:
STEP 1: Start
STEP 3: If num=0
STEP 5: else
STEP 6: towers(num-1,frompeg,auxpeg,topeg);
STEP 8: towers(num-1,auxpeg,topeg,frompeg)
STEP 9: endif
PROGRAM
#include<stdio.h>
void towers(int,char,char,char);
int main()
{
int num;
printf("Enter the number of disks: ");
scanf("%d",&num);
printf("The sequence of moves involved in the tower of Hanoi are: \n");
towers(num,'A','C','B');
return 0;
}
void towers(int num,char frompeg,char topeg,char auxpeg)
{
if(num==1)
{
printf("\n Move disk 1 from peg %c to peg %c",frompeg,topeg);
return;
}
towers(num-1,frompeg,auxpeg,topeg);
printf("\n Move disk %d from peg %c to peg %c",num,frompeg,topeg);
towers(num-1,auxpeg,topeg,frompeg);
}
OUTPUT:
RESULT:
INCREMENTING DATE
#include <stdio.h>
#include<time.h>
void main()
{
struct tm date = {0} ;
time_t timer;
clrscr();
timer=time(NULL);
date = *gmtime( &timer ) ;
//printf(“%s”,asctime(localtime(&timer)));
printf("%d/%d/%d\n",date.tm_mday-1,date.tm_mon+1,date.tm_year+1900);
date.tm_year = date.tm_year;
date.tm_mon = date.tm_mon;
date.tm_mday = date.tm_mday + 1;
timer = mktime( &date ) ;
date = *gmtime( &timer ) ;
//printf(“%s”,asctime(localtime(&timer)));
printf("%d/%d/%d\n",date.tm_mday-1,date.tm_mon+1,date.tm_year+1900);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("Enter Day No:-> ");
scanf("%d",&n);
switch(n)
{
case 1:
printf("Monday \n");
break;
case 2:
printf("Tuesday \n");
break;
case 3:
printf("Wednesday \n");
break;
case 4:
printf("Thursday \n");
break;
case 5:
printf("Friday \n");
break;
case 6:
printf("Saturday \n");
break;
case 7:
printf("Sunday \n");
break;
default:
printf("invalid day number\nPlease try again ....\n");
break;
}
getch();
}
PHASE – II
#include<stdio.h>
int main()
{
int i, n, lar,sm, elem;
printf ("Enter total number of elements \n");
scanf ("%d", &elem);
printf ("Enter first number \n");
scanf ("%d", &n);
lar = n;
sm=n;
for (i=1; i<= elem -1 ; i++)
{
printf ("\n Enter another number \n");
scanf ("%d",&n);
if (n>lar)
lar=n;
if (n<sm)
sm=n;
}
printf ("\n The largest number is %d", lar);
printf ("\n The smallest number is %d", sm);
return 0;
}
AIM:
To convert the given decimal number into binary, octal and hexadecimal numbers using user
defined functions
ALGORITHM:
STEP 1:Start
STEP 6: Stop
PROGRAM:
#include<stdio.h>
FILE *FP=NULL;
void main()
{
int ch,num;
void octal(int);
void binary(int);
void hexa(int);
clrscr();
printf("Enter decimal number to be converted : \n");
scanf("%d",&num);
printf("\nselect Conversion");
printf("\n 1. Decimal To Binary\n");
printf("\n 2. Decimal To Octal\n");
printf("\n 3. Decimal To Hexadecimal\n");
printf("\nEnter Your Choice:");
scanf("%d",&ch);
switch(ch)
{
case 1 : binary(num);
printf("\nouput Written To Output.Txt");
break;
case 2 : octal(num);
printf("\nouput Written To Output.Txt");
break;
case 3 : hexa(num);
printf("\nouput Written To Output.Txt");
break;
default : printf("\nYou Have Entered Wrong Choice !!!");
}
getch();
}
void hexa(int y)
{
char hexc[5];
int num,i,n,len,hexd[5];
num=y;
len=0;
while(y>0)
{
hexd[len]=y%16;
y=y/16;
len++;
};
for(i=len-1;i>-1;i--)
{
if(hexd[i]<10)
hexc[i]=hexd[i]+48;
else
hexc[i]=hexd[i]+55;
}
if((FP=fopen("output.txt","a+t"))==NULL)
{
printf("File Can't Be Opened Or Created\n");
exit(0);
}
fprintf(FP,"\nConverted hexa Equivalent Value Of %d is \t",num);
for(i=len-1;i>-1;i--)
{
fprintf(FP,"%c",hexc[i]);
}
}
void binary(int y)
{
int num,i,len,bin[20];
num=y;
len=0;
while(y>0)
{
bin[len]=y%2;
y=y/2;
len++;
};
if((FP=fopen("output.txt","a+t"))==NULL)
{
printf("File Can't Be Opened Or Created\n");
exit(0);
}
fprintf(FP,"%d",bin[i]);
}
}
void octal(int y)
{
int num,i,len,oct[5];
num=y;
len=0;
while(y>0)
{
oct[len]=y%8;
y=y/8;
len++;
};
if((FP=fopen("output.txt","a+t"))==NULL)
{
printf("File Can't Be Opened Or Created\n");
exit(0);
}
fprintf(FP,"\nConverted Octal Equivalent Value Of %d is \t",num);
for(I=LEN-1;I>-1;I--)
{
fprintf(FP,"%d",oct[i]);
}
}
OUTPUT:
OBS
REC
VIVA
TOTAL
RESULT:
ASCENDING ORDER
#include <stdio.h>
sort_numbers_ascending(number, count);
}
DESCENDING ORDER
#include <stdio.h>
void main()
{
int arr1[100];
int n, i, j, tmp;
MATRIX ADDITION
#include <stdio.h>
int main()
{
int m, n, c, d, first[10][10], second[10][10], sum[10][10];
return 0;
}
MATRIX SUBTRACTION
#include <stdio.h>
int main()
{
int m, n, c, d, first[10][10], second[10][10], difference[10][10];
return 0;
}
TRANSPOSE MATRIX
#include <stdio.h>
int main()
{
int m, n, c, d, matrix[10][10], transpose[10][10];
return 0;
}
AIM:
To print the reverse of a string without changing the position of special characters
ALGORITHM:
STEP 1: Start
STEP 6: elseif(!isalpha(s[r]))
STEP 9: Stop
PROGRAM:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void swap(char *a, char *b)
{
char temp = *a;
*a = *b;
*b = temp;
}
void reverse(char *str)
{
char *p1 = str;
char *p2 = str + strlen(str) - 1;
while (p1 < p2) {
while (!isalpha(*p1)) p1++;
while (!isalpha(*p2)) p2--;
if (p1 < p2) {
swap(p1, p2);
p1++;
p2--;
}
}
}
int main(void)
{
char str[6];
strcpy(str, "a$bcd./$ef");
reverse(str);
printf("%s\n", str);
return 0;
} OBS
REC
OUTPUT
VIVA
f$edc./$ba
TOTAL
RESULT:
AIM:
ALGORITHM:
STEP 1: Start
STEP 4: if s[i]==’’
STEP 6: Endif
STEP 7: endfor
STEP 8: Stop
PROGRAM
#include<stdio.h>
#include<string.h>
void main()
{
char s[200];
int count=0,i;
printf("\n Enter the string: ");
scanf("%l[^\n]s",&s);
for(i=0;s[i]!='\0';i++)
{
if(s[i]== ' ')
count++;
}
printf("Number of words in given string are: %d\n",count+1);
OUTPUT:
OBS
REC
VIVA
TOTAL
RESULT:
AIM
ALGORITHM
STEP 1: Start
STEP 5: str[i]=str[i]-32
STEP 6: end if
STEP 8: str[i]=str[i]-32
PROGRAM
#include<stdio.h>
#define MAX 100
int main()
{
char str[MAX]={0};
int i;
printf("Enter a string:");
scanf("%l[^\n]s",str);
for(i=0;str[i]!='\0';i++)
{
if(i==0)
{
if((str[i]>='a'&&str[i]<='z'))
str[i]=str[i]-32;
continue;
}
if(str[i]==' ')
{
++i;
if(str[i]>='a'&& str[i]<='z')
{
str[i]=str[i]-32;
continue;
}
}
else
{
if(str[i]>='A' && str[i]<='Z')
str[i]=str[i]+32;
}
}
printf("Capitalize string is: %s\n",str);
return 0;
}
OUTPUT:
OBS
REC
VIVA
TOTAL
RESULT:
AIM:
ALGORITHM:
STEP 1: Start
STEP 5: Stop
PROGRAM:
#include <stdio.h>
#include <string.h>
#include<conio.h>
void main()
{
char text[100],word[10],rpwrd[10],str[10][10];
int i=0,j=0,k=0,w,p;
clrscr();
printf(“\n Enter any Text: “);
gets(text);
printf("\n Enter which word to be replaced\n");
scanf("%s",word);
printf("\n Enter the word %s to be replaced \n",word);
scanf("%s",rpwrd);
p=strlen(text);
for (k=0; k<p; k++)
{
if (text[k]!=' ')
{
str[i][j] = text[k];
j++;
}
else
{
str[i][j]='\0';
j=0;
DEPARTMENT OF SCIENCE AND HUMANITIES – CSE - II - SEMESTER Page 51
4213 – KCET CS8261-C PROGRAMMING LAB MANUAL R-2017
i++;
}
}
str[i][j]='\0';
w=i;
for (i=0; i<=w; i++)
{
if(strcmp(str[i],word)==0)
strcpy(str[i],rpwrd);
printf("%s ",str[i]);
}
getch();
}
OUTPUT:
Welcome was CSE department
Enter which word to be replaced
was
Enter the word was to be replaced
To
Welcome To CSE department
OBS
REC
VIVA
TOTAL
RESULT:
#include <stdio.h>
int main()
int x, y, t;
t = x;
x = y;
y = t;
return 0;
STRING OPERATION
#include <stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
void main() {
do {
printf("\n1.Length of a string");
printf("\n4.Copy");
printf("\n5.String Comparison");
printf("\n6.String Concatenation");
printf("\n7.String Searching");
printf("\n9.Quit");
scanf("%d", &option);
flushall();
switch (option) {
case 1:
printf("\nEnter a String:");
gets(a);
result = length(a);
printf("\nPress a Character");
getch();
break;
case 2:
printf("\nEnter a String:");
gets(a);
reverse(a);
printf("\nResult=%s", a);
printf("\nPress a Character");
getch();
break;
case 3:
gets(a);
result = palindrome(a);
if (result == 0)
printf("\nNot a palindrome");
else
printf("\nA palindrome");
printf("\nPress a Character");
getch();
break;
case 4:
printf("\nEnter a String:");
gets(a);
copy(b, a);
printf("\nResult=%s", b);
printf("\nPress a Character");
getch();
break;
case 5:
gets(a);
gets(b);
if (result == 0)
printf("\n1st>2nd");
else
printf("\n1st<2nd");
printf("\nPress a Character");
getch();
break;
case 6:
gets(a);
gets(b);
concat(a, b);
printf("\nresult=%s", a);
printf("\nPress a Character");
getch();
break;
case 7:
gets(a);
gets(b);
search(a, b);
printf("\nPress a Character");
getch();
break;
case 8:
printf("\nEnter a string:");
gets(a);
count(a);
printf("\nPress a Character");
getch();
break;
default:
printf("\nInvalid Choice:");
break;
int i = 0;
i++;
return (i);
int i, j;
char temp;
i = j = 0;
j++;
j--;
while (i < j) {
temp = str[i];
str[i] = str[j];
str[j] = temp;
i++;
j--;
int i, j;
i = j = 0;
j++;
while (i < j) {
return (0);
i++;
j--;
return (1);
int i = 0;
str2[i] = str1[i];
i++;
str2[i] = '\0';
int i;
i = 0;
return (1);
return (-1);
i++;
return (0);
int i, j;
i = 0;
i++;
str1[i] = str2[j];
str1[i] = '\0';
if (str2[j] == '\0')
words++;
characters++;
spchar++;
SORTING NAMES
#include<stdio.h>
#include<string.h>
int main(){
int i,j,count;
char str[25][25],temp[25];
scanf("%d",&count);
for(i=0;i<=count;i++)
gets(str[i]);
for(i=0;i<=count;i++)
for(j=i+1;j<=count;j++){
if(strcmp(str[i],str[j])>0){
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
for(i=0;i<=count;i++)
puts(str[i]);
return 0;
#include <stdio.h>
#include <string.h>
int main()
char string[1000];
gets(string);
return 0;
#include <stdio.h>
int main()
int n, num = 0;
scanf("%d", &n);
while(n != 0)
n /= 10;
while(num != 0)
switch(num % 10)
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
return 0;
SORTING NAMES
#include<stdio.h>
#include<string.h>
int main(){
int i,j,count;
char str[25][25],temp[25];
scanf("%d",&count);
for(i=0;i<=count;i++)
gets(str[i]);
for(i=0;i<=count;i++)
for(j=i+1;j<=count;j++){
if(strcmp(str[i],str[j])>0){
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
for(i=0;i<=count;i++)
puts(str[i]);
return 0;
PHASE – III
AIM:
ALGORITHM
STEP 1: Start
STEP 5: Stop
PROGRAM
#include<stdio.h>
#include<string.h>
#include<conio.h>
union employee
{
char ename[30];
int eno;
float bsal;
};
void main()
{
union employee emp; char name[30];
int id;
float basic,hra,da,tds,net,gross; clrscr();
printf("\Employee Payroll Processing\n");
printf("\----------------------------------\n");
printf("\nDetails of the Employee\n\n");
printf("\nEnter the Employee Name: ");
scanf("%s",emp.ename);
strcpy(name,emp.ename);
printf("\nEnter the Employee Id: ");
scanf("%d",&emp.eno);
id=emp.eno;
printf("\nEnter the Basic Salary: ");
scanf("%f",&emp.bsal);
basic=emp.bsal;
hra=basic*.10;
da=basic*.35;
tds=basic*.15;
gross=basic+hra+da;
net=gross-tds;
printf("\n\nSALARY DETAILS FOR THE MONTH\n");
printf("\n------------------------------------------------------\n");
printf("\n\nEmployee Name\t: %s",name);
printf("\n\nEmployee No.\t: %d",id);
printf("\n\nBasic salary\t: %.2f",basic);
printf("\n\nHRA\t\t: %.2f",hra);
printf("\n\nDA\t\t: %.2f",da);
printf("\n\nTDS\t\t: %.2f",tds);
printf("\n\nGross Salary\t: %.2f",gross);
printf("\n\nNet Salary\t: %.2f",net);
getch();
}
OUTPUT:
----------------------------------------------------
OBS
REC
VIVA
TOTAL
RESULT:
AIM:
To insert, update, delete and append telephone details of an individual or a company into a
telephone directory using random access file
ALGORITHM
STEP 1: Start
STEP 3: switch(choice)
STEP 7: Stop
PROGRAM
#include <stdio.h>
#include <conio.h>
#include <string.h>
struct person{
char name[20];
long telno;
};
void appendData(){
FILE *fp;
struct person obj;
clrscr();
fp=fopen("data.txt","a");
printf("*****Add Record****\n");
printf("Enter Name : ");
scanf("%s",obj.name);
printf("Enter Telephone No. : ");
scanf("%ld",&obj.telno);
fprintf(fp,"%20s %7ld",obj.name,obj.telno);
fclose(fp);
}
void showAllData()
{
FILE *fp;
struct person obj;
clrscr();
fp=fopen("data.txt","r");
printf("*****Display All Records*****\n");
printf("\n\n\t\tName\t\t\tTelephone No.");
printf("\n\t\t=====\t\t\t===============\n\n");
while(!feof(fp))
{
fscanf(fp,"%20s %7ld",obj.name,&obj.telno);
printf("%20s %30ld\n",obj.name,obj.telno);
}
fclose(fp);
getch();
}
void findData(){
FILE *fp;
struct person obj;
char name[20];
int totrec=0;
clrscr();
fp=fopen("data.txt","r");
case'2' :
findData();
break;
case'3' : showAllData();
break;
case'4' : exit();
}
}
}
OUTPUT
*****TELEPHONE DIRECTORY*****
1) Append Record
2) Find Record
3) Read all record
4) Exit
Enter your choice : 1
*****Add Record****
Enter Name : ram
Enter Telephone No. : 9521743851
*****TELEPHONE DIRECTORY*****
1) Append Record
2) Find Record
3) Read all record
4) Exit
Enter your choice : 1
*****Add Record****
Enter Name : srivani
Enter Telephone No. : 9685427162
*****TELEPHONE DIRECTORY*****
1) Append Record
2) Find Record
3) Read all record
4) Exit
Enter your choice : 1
*****Add Record****
Enter Name : Sushmitha
Enter Telephone No. : 8514357490
*****TELEPHONE DIRECTORY*****
1) Append Record
2) Find Record
3) Read all record
4) Exit
Enter your choice : 2
*****TELEPHONE DIRECTORY*****
1) Append Record
2) Find Record
3) Read all record
4) Exit
Enter your choice : 3
RESULT:
MINI PROJECT
AIM:
Booking
Availability checking
Cancellation
Prepare Chart
ALGORITHM
STEP 1: Start
STEP 6: if a->seat>70
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int seat;
char name[15];
int age;
char sex;
struct node* next;
}list,*ptr;
void delete(ptr a);
void add(ptr a);
void printseat(ptr temp);
void print(ptr a);
void delete(ptr a);
int main()
{
int i,input;
ptr a;
a=(ptr)malloc(1*sizeof(list)); // dummy node
a->next=NULL;
a->seat=0;
for(i=0;i<100;i++)
{
printf(“\n 1 Book a ticket \n2 Deleting a TICKET \n3 Print the chart \n4 Exit the loop \n");
scanf("%d",&input);
if(input==1)
{
add(a);
}
else if(input==2)
{
delete(a);
}
else if(input==3)
{
print(a);
}
else if(input==4)
{
break;
}
else
{
printf("not able to recognise the command \n");
}
}
printf("thank you \n");
return 0;
}
void add(ptr a)
{
int input,input2;
ptr temp=NULL;
while(a->next!=NULL)
{
a=a->next;
}
if(a->seat>70)
{
printf("train full \n");
return ;
}
else if(a->seat>50)
{
printf("%d waiting available \n",(a->seat)-50);
printf("enter 1 to exit 0 to continue ");
scanf("%d",&input2);
if(input2==1)
{
return ;
}
}
temp=(ptr)malloc(1*sizeof(list));
temp->next=NULL;
printf("enter name ");
scanf("%s",temp->name);
printf("enter age ");
scanf("%d",&temp->age);
printf("enter sex ");
scanf("%s",&temp->sex);
temp->seat=(a->seat)+1;
printf("Enter 1 to print the ticket \n 0 for not to print the ticket \n");
scanf("%d",&input);
if(input==1)
{
printseat(temp);
}
a->next=temp;
return ;
}
void printseat(ptr temp)
{
if(temp->seat>50)
{
printf("WL=%d",(temp->seat)-50);
}
Else
{
printf("confirm seat=%d",temp->seat);
}
printf(" name=%s ",temp->name);
printf("sex=%c ",temp->sex);
printf("age=%d \n",temp->age);
return ;
}
void print(ptr a)
{
a=a->next;
while(a!=NULL)
{
printf("seat number=%d,name=%s ,age=%d,sex=%c \n",a->seat,a->name,a->age,a->sex);
a=a->next;
}
return ;
}
void delete(ptr a)
{
int input;
ptr temp;
a=a->next;
printf("enter the seat number ");
scanf("%d",&input);
while(a!=NULL&&(a->seat)!=input)
{
a=a->next;
}
if(a==NULL)
{
printf("can not delete \n");
return ;
}
temp=a;
a=a->next;
free(temp);
while(a!=NULL)
{
a->seat=a->seat-1;
a=a->next;
}
printf("seat deleted \n");
return ;
}
OUTPUT:
1 Book a ticket
2 Deleting a TICKET
3 Print the chart
4 Exit the loop
Enter name:Ram
Enter age:20
Enter sex:male
Enter 1 to print the ticket
0 for not to print the ticket
0
1 Book a ticket
2 Deleting a TICKET
3 Print the chart
4 Exit the loop
1
Enter name:Balaji
Enter age:50
Enter sex:male
Enter 1 to print the ticket
0 for not to print the ticket
1 Book a ticket
2 Deleting a TICKET
3 Print the chart
4 Exit the loop
3
Seat number=1,name=Ram,age=20,sex=male
Seat number=2,name=Balaji,age=50,sex=male
OBS
REC
VIVA
TOTAL
RESULT: