SlideShare a Scribd company logo
1 of 74
kala
Experiment No. 1
Date:
AIM: TO FIND SIMPLE INTEREST AND COMPOUND INTEREST
ALGORITHM:
Step 1: Start
Step 2: Declare variables p,r,t,si,ci,amount as float.
Step 3: Accept values for p,r,t,n.
Step 4: Calculate si=p*t*r/100
Step 5: Calculate amount=p* pow((1+r/n*100),n*t)
Step 6: Calculate ci=amount-p
Step 7: Print
Step 8: Stop
C’ software lab - 1 - MCA’05
/*Simple interest and compound interest*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float p,r,t,si,ci,amount;
int n;
clrscr();
printf("nEnter principle :");
scanf("%f",&p);
printf("nEnter rate :");
scanf("%f",&r);
printf("nEnter time :");
scanf("%f",&t);
printf("nEnter compoundings per year :");
scanf("%d",&n);
si=(p*t*r)/100;
printf("nSimple Interest =%7.2f",si);
amount=p*pow((double)(1+r/(n*100)),(double)(n*t));
ci=amount-p;
printf("nCompond Interest=%7.2fn",ci);
getch();
}
C’ software lab - 2 - MCA’05
OUTPUT :
Enter principle :10000
Enter rate :8
Enter time :4
Enter compoundings per year :2
Simple Interest =3200.00
Compond Interest=3685.69
C’ software lab - 3 - MCA’05
Experiment No. 2
Date:
AIM : TO FIND THE AMSTRONG NUMBER AMONG THE GIVEN NUMBERS
ALGORITHM :
Step1: Start
Step2: Accept a Number
Step3: Assign the number to another variable
Step4: Check whether the no is greater than Zero go to step 8
Step5: Extract the last digit and add the cube to a sum variable
Step6: Divde the number by 10
Step7: Goto step 4
Step8: Check whether the sum = temporary variable and print result
Step9: Stop
C’ software lab - 4 - MCA’05
/*Armstrong number*/
#include<stdio.h>
#include<conio.h>
void main()
{
int num,arms=0,tmp,mod;
clrscr();
printf("n Enter the number :");
scanf("%d",&num);
tmp=num;
while(num>0)
{
mod=num%10;
arms+=mod*mod*mod;
num=num/10;
}
if(tmp==arms)
printf("n Number %d is armstrong",arms);
else
printf("n Number %d is not armstrong",tmp);
getch();
}
C’ software lab - 5 - MCA’05
OUTPUT :
1. Enter the number :153
Number 153 is armstrong
2. Enter the number :111
Number 111 is not armstrong
C’ software lab - 6 - MCA’05
Experiment No. 3
Date:
AIM : TO FIND THE ROOTS OF A QUADRATIC EQUATION
ALGORITHM :
Step1: Start
Step2: Accept values for the variables x2 x and constant
Step3: Apply the formula b2-4ac (b=cof x2,a=cof x,c=constant) as save to a variable
Step4: Check whether the value is less than 0 then print roots are imaginary
Step5: If value=0 then print the roots are equal –b/2a
Step6: If value greater than 0, 1st root is (-b+sqrt(value))/(2*a),
2nd root is (-b-sqrt(value))/(2*a).
Step7: Print the result
Step8: Stop
C’ software lab - 7 - MCA’05
/*Quadratic Equation*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,d,r1,r2;
clrscr();
printf("n Enter the Coeff. of the Eq. :");
scanf("%f%f%f",&a,&b,&c);
d=(b*b)-(4*a*c);
if(d==0)
{
printf("n Roots are REAL and EQUAL");
r1=-b/(2*a);
printf("n Root Is : %.2f",r1);
}
else if (d>0)
{
printf("n Roots are Real and Distinct");
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
printf("n Root 1 : %.2f ..... Root 2 : %.2f",r1,r2);
}
else
{
printf("n Roots are imaginary");
}
getch();
}
C’ software lab - 8 - MCA’05
OUTPUT :
1.Enter the Coeff. of the Eq. :1 -5 6
Roots are Real and Distinct
Root 1 : 3.00 ..... Root 2 : 2.00
2.Enter the Coeff. of the Eq. :4 4 1
Roots are REAL and EQUAL
Root Is : -0.50
C’ software lab - 9 - MCA’05
Experiment No. 4
Date:
AIM : TO PERFORM MATRICS ADDITION, MULTIPLICATION. TRANSPOSE.
ALGORITHM :
Step 1: Start
Step 2: Declare three integer 2 dimensional array of order 3*3 .
Step 3: Accept a choice from user
Step 4: If choice = 1 : goto Step 9
Step 5: If choice = 2 : goto Step 10
Step 6: If choice = 3 : goto step 11
Step 7: else if choice = 4 : goto Step 12
Step 8: Accept the elements of the two 2 D arrays
Step 9: If choice = 1
a. Add the elements that belong corresponding cells in the arrays and store in
third array’s respective cell.
b. Display the result.
Step 10 : If choice = 2
a. Multiply the elements of the first two matrices and store the result in third
array.
b. Display the result.
Step 11 : If choice = 3
a. Accept the elements of the matrics one.
b. Display the matrics in the order column*row format.
Step 13 : Repeat step 3 to 11.
Step 14 : Stop.
C’ software lab - 10 - MCA’05
/*Matrics Addition, Multiplication, Transpose*/
#include<stdio.h>
#include<conio.h>
int a[10][10],b[10][10],c[10][10],r1,r2,c1,c2,i,j,k,ch;
void add();
void mul();
void tran();
void accept(int [][10],int,int);
void display(int [][10],int,int);
void main()
{
clrscr();
do
{
clrscr();
printf("n Matrix Manipulator");
printf("n 1.Addition");
printf("n 2.Multiplication");
printf("n 3.Transpose");
printf("n press any other key to exit...");
printf("n Enter U'r choice :");
scanf("%d",&ch);
if (ch>=1&&ch<=3)
{
printf("n Enter order of the matrices :");
printf("n Mat 1 :");
scanf("%d%d",&r1,&c1);
printf("n Mat 2 :");
scanf("%d%d",&r2,&c2);
}
switch(ch)
{
C’ software lab - 11 - MCA’05
case 1:
if((r1==r2)&&(c1==c2))
add();
else
printf("n addition not possible...");
getch();
break;
case 2:
if(c1==r2)
mul();
else
printf("n multiplication not possible...");
getch();
break;
case 3: tran();getch();break;
default: printf("n Wrong choice Exit...");
}
}while(ch>0&&ch<4);
getch();
}
void add()
{
printf("n Matrics addition");
printf("n Enter Matrics 1:");
accept(a,r1,c1);
printf("n Enter Matrics 2:");
accept(b,r2,c2);
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)
c[i][j]= a[i][j]+b[i][j];
printf("n Matrics A :n");
C’ software lab - 12 - MCA’05
display(a,r1,c1);
printf("n Matrics B :n");
display(b,r2,c2);
printf("n Matrics C :n");
display(c,r1,c2);
}
void mul()
{
printf("n Matrics multiplication");
printf("n Enter Matrics 1:");
accept(a,r1,c1);
printf("n Enter Matrics 2:");
accept(b,r2,c2);
for(i=0;i<r1;i++)
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<c1;k++)
c[i][j] += a[i][k]*b[k][j];
}
printf("n Matrics A :n");
display(a,r1,c1);
printf("n Matrics B :n");
display(b,r2,c2);
printf("n Matrics C :n");
display(c,r1,c2);
}
void tran()
{
printf("n Matrics Transpose");
C’ software lab - 13 - MCA’05
printf("n Enter Matrics :n");
accept(a,r1,c1);
display(a,r1,c1);
printf("n Transposed Matrics :n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%dt",a[j][i]);
}
printf("n");
}
}
void display(int x[][10],int m,int n)
{
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%dt",x[i][j]);
}
printf("n");
}
}
void accept(int x[][10],int m,int n)
{
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
C’ software lab - 14 - MCA’05
scanf("%d",&x[i][j]);
}
}
}
C’ software lab - 15 - MCA’05
OUTPUT :
Matrix Manipulator
1.Addition
2.Multiplication
3.Transpose
press any other key to exit...
Enter U'r choice :3
Enter order of the matrices :
Mat 1 :3 3
Mat 2 :2 2
Matrics Transpose
Enter Matrics :
1 2 3
2 3 4
3 4 5
1 2 3
2 3 4
3 4 5
Transposed Matrics :
1 2 3
2 3 4
3 4 5
C’ software lab - 16 - MCA’05
Experiment No. 5
Date:
AIM : TO FIND OUT REVERSE OF A GIVEN NUMBER
ALGORITHM :
Step 1: Start
Step 2: Declare variables n, dig, rev=0 as integer.
Step 3: Input the number, n.
Step 4: If n>0 then goto step 5 else goto step 8
Step 5: Modular division is done on the number with 10 .The value obtained
is assigned to variable
Step 6: The variable, rev is multiplied by 10 and then added with the variable dig,
thisvalue is assigned to rev.
Step 7: The variable, n is divided by 10 and the result is stored in n. Goto step 4
Step 8: The result is displayed on the screen
Step 9: Stop
C’ software lab - 17 - MCA’05
/*Reverse of a Number*/
#include<stdio.h>
#include<conio.h>
void main()
{
int num,rnum=0,mod;
clrscr();
printf("n Enter the Number :");
scanf("%d",&num);
while(num>0)
{
mod=num%10;
rnum=rnum*10+mod;
num=num/10;
}
printf("n reverse of number is %d",rnum);
getch();
}
C’ software lab - 18 - MCA’05
OUTPUT :
Enter the Number :1234
reverse of number is 4321
C’ software lab - 19 - MCA’05
Experiment No. 6
Date:
AIM : PERFORM SORTING A ONE DIMENSIONAL
ALGORITHM :
Step 1 : Start
Step 2 : Read the limit, N
Step 3 : Read elements of A[N] using for loop
Step 4 : Using for loop check whether A[I]>A[J] if yes then proceed
Step 5 : tA[I]
Step 6 : A[I]A[J]
Step 7 : A[J]t
Step 8 : End If
Step 9 : End for
Step 10 : Print Sorted array A[N]
Step 11 : Stop
C’ software lab - 20 - MCA’05
/*Sorting a 1-D array*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[15],i,tmp,j,k;
clrscr();
printf("n Enter the Size :");
scanf("%i",&i);
printf("n Enter the elements in the array : n");
for(j=0;j<i;j++)
{
scanf("%d",&a[j]);
}
printf("n Entered Elements are : n");
for(j=0;j<i;j++)
{
printf("%dt",a[j]);
}
for(j=0;j<i;j++)
{
for(k=j;k<i;k++)
{
if(a[j]>a[k])
{
tmp = a[j];
a[j]= a[k];
a[k]=tmp;
}
}
}
printf("n Sorted Elements are : n");
C’ software lab - 21 - MCA’05
for(j=0;j<i;j++)
{
printf("%dt",a[j]);
}
getch();
}
C’ software lab - 22 - MCA’05
OUTPUT :
Enter the Size :8
Enter the elements in the array :
3 7 5 9 7 4 3
8
Entered Elements are :
3 7 5 9 7 4 3 8
Sorted Elements are :
3 3 4 5 7 7 8 9
C’ software lab - 23 - MCA’05
Experiment No. 7
Date:
AIM : TO PROGRAM FOR SORT THE ENTERED STRINGS IN ALPHABETIC
ORDER.
ALGORITHM :
Step 1: Start
Step 2: Accept a single dimensional array, also declare another temporary array
Step 3: Sort the elements of the vector in ascending order
Step 4: Extract numbers one by one from main vector and check whether
the number is equal to the previous number if no’s are different insert it into
the
temporary array.
step 5: Print the temporary Array to see the result
step 6: Stop
C’ software lab - 24 - MCA’05
/*Deleting Duplicates in a 1-D array*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[15],i,tmp,j,k;
clrscr();
printf("n Enter the Size :");
scanf("%i",&i);
printf("n Enter the elements in the array : n");
for(j=0;j<i;j++)
{
scanf("%d",&a[j]);
}
printf("n Entered Elements are : n");
for(j=0;j<i;j++)
{
printf("%dt",a[j]);
}
for(j=0;j<i;j++)
{
for(k=j;k<i;k++)
{
if(a[j]>a[k])
{
tmp = a[j];
a[j]= a[k];
a[k]=tmp;
}
}
}
for(j=0;j<i;j++)
C’ software lab - 25 - MCA’05
{
if(a[j]==a[j+1])
{
for(k=j;k<i;k++)
{
a[k]=a[k+1];
}
i--;j--;
}
}
printf("n Sorted Elements are : n");
for(j=0;j<i;j++)
{
printf("%dt",a[j]);
}
getch();
}
C’ software lab - 26 - MCA’05
OUTPUT :
Enter the Size :8
Enter the elements in the array :
6
5
8
4
2
6
8
5
Entered Elements are :
6 5 8 4 2 6 8 5
Sorted Elements are :
2 4 5 6 8
C’ software lab - 27 - MCA’05
Experiment No. 8
Date:
AIM : WRITE A PROGRAM TO PRINT FIBONACCI SERIES.
ALGORITHM :
Step 1: Start
Step 2: Declare variables n,a=0,b=1,c,i=1 as integer.
Step 3: Input value of n.
Step 4: Value of n is decremented by 1.
Step 5: The sum of a and b is assigned to c.
Step 6: The value c is displayed.
Step 7: The value of b is assigned to a and value of c is assigned to b.
Step 8: value of i is incremented by 1
Step 9: If i<n then goto step 6 Else goto step 10.
Step 10: Stop.
C’ software lab - 28 - MCA’05
/*Fibonacci Series*/
#include<stdio.h>
#include<conio.h>
void main()
{
int f=1,s=0,t,r,i;
clrscr();
printf("n Enter the range :");
scanf("%d",&t);
printf("n Fibonacci Series...in %d numbers is...",t);
printf("n%d ",s);
for(i=0;i<t-1;i++)
{
r=f+s;
f=s;
s=r;
printf(" %d ",r);
}
getch();
}
C’ software lab - 29 - MCA’05
OUTPUT :
Enter the range :8
Fibonacci Series...in 8 numbers is...
0 1 1 2 3 5 8 13
C’ software lab - 30 - MCA’05
Experiment No. 9
Date :
AIM : TO PERFORM THE FUNCTIONS OF A CALCULATOR USING SWITCH
CASE AND FUNCTIONS.
ALGORITHM :
Step 1 : Start
Step 2 : Read choice 1.Add 2.Sub 3.Mul 4.Div.
Step 3 : If choice =1 then add the numbers
Step 4 : If choice =2 then subtract the numbers.
Step 5 : If choice = 3 then multiply the numbers.
Step 6 : If choice = 4 then divide the numbers
Step 7 : Display respective output.
Step 8 : Stop
C’ software lab - 31 - MCA’05
/*Calculator*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int a,b;
int ch;
do
{
clrscr();
printf("nnnnnnn");
printf("ttttCALCULATORnnnn");
printf("ttt1.Additionn");
printf("ttt2.Substractionn");
printf("ttt3.Multiplicationn");
printf("ttt4.Divisionn");
printf("ttt5.Exit");
printf("nnntttEnter U'r choice :");
scanf("%d",&ch);
if(ch<5)
{ printf("ntttEnter two values:");
scanf("%d %d",&a,&b);
}
else exit(0);
switch(ch)
{
case 1:
printf("tttThe sum is :%d",a+b); getch();break;
case 2:
printf("tttThe diference is :%d",a-b);getch();break;
case 3:
C’ software lab - 32 - MCA’05
printf("tttThe multiplication is :%d",a*b);getch();break;
case 4:
if(b==0) printf("tttDivide by zero error");
else
printf("tttTHe division is :%d",a/b);getch();
break;
case 5: exit(0);
}
}while(ch<6);
getch();
}
C’ software lab - 33 - MCA’05
OUTPUT :
CALCULATOR
1.Addition
2.Substraction
3.Multiplication
4.Division
5.Exit
Enter U'r choice :1
Enter two values:1 18
The sum is :19
CALCULATOR
1.Addition
2.Substraction
3.Multiplication
4.Division
5.Exit
Enter U'r choice :4
Enter two values:18 1
THe division is :18
C’ software lab - 34 - MCA’05
Experiment No.10
Date:
AIM : TO WRITE A PROGRAM TO CREATE AND MANIPULATE STUDENTS
RECORD USING STRUCTURES AND POINTERS.
ALGORITHM :
Step 1 : Start
Step 2 : Declare structure Stud
Roll_no as Integer
Name as Character array
Grade as Character
Mark, as an integer array
Step 3 : Create student object as an array as st[10], and also a pointer object *sd
Step 4 : Declare tot_mark, n
Step 5 : Accept number of entries as n
Step 6 : Accept student details
Step 7 : Calculate the average of students as sum of marks / 3
Step 8 : Calculate the grades and store to structure as on the conditions
if average > = 80 : grade = A
if average > = 60 and average < 80 : grade = B
if average > = 50 and average < 60 : grade = c
else if average < 50 : grade = Failed
Step 9 : Print details of students as per fields in the structure
Step 10 : Stop
C’ software lab - 35 - MCA’05
/*Student’s Record Using Poinetrs*/
#include<stdio.h>
#include<conio.h>
struct stud
{
int regno;
char name[20];
int mark[3];
char grade;
}s[10],*st;
void main()
{
int i,avg=0,j,num;
clrscr();
printf("n Enter the number of students...");
scanf("%d",&num);
st = s;
for(i=0;i<num;i++)
{
printf("n Enter student's Details :");
printf("n Roll no :");
scanf("%d",&st->regno);
printf(" Name :");
scanf("%s",st->name);
for(j=0;j<3;j++)
{
printf(" mark %d :",j+1);
scanf("%d",&st->mark[j]);
avg+=st->mark[j];
}
printf("Average of %s is %d",st->name,avg=avg/3);
C’ software lab - 36 - MCA’05
if(avg>=80)
st->grade='A';
else if(avg>=60 && avg<80)
st->grade='B';
else if(avg>=50 && avg<60)
st->grade='C';
else
st->grade='F';
st++;
avg=0;
}
st=s;
printf("n Student details...");
printf("nReg_notNamettMarkst1t2t3tgrade");
for(i=0;i<num;i++)
{
printf("n%dt%sttt%dt%dt%dt%c",st->regno,st->name,st->mark[0],st-
>mark[1],st->mark[2],st->grade);
st++;
}
getch();
}
C’ software lab - 37 - MCA’05
OUTPUT :
Enter the number of students...2
Enter student's Details :
Roll no :1
Name :Sachin
mark 1 :75
mark 2 :85
mark 3 :80
Average of Sachin is 80
Enter student's Details :
Roll no :2
Name :Rohit
mark 1 :80
mark 2 :65
mark 3 :82
Average of Rohit is 75
Student details...
Reg_no Name Marks 1 2 3 grade
1 Sachin 75 85 80 A
2 Rohit 80 65 82 B
C’ software lab - 38 - MCA’05
Experiment No. 11
Date:
AIM : TO PERFORM, SORT A CHARACTER ARRAY IN ACSENDING ORDER
ALGORITHM :
Step 1: Start
Step 2: Accept a character array
Step 3: use a for loop to extract characters from the array and check it with each
characters of the array if value is greater interchange the value in the positon
Step 4: Display the result
Step 5: Stop
C’ software lab - 39 - MCA’05
/*Sorting a 1-D Charater array*/
#include<stdio.h>
#include<conio.h>
void main()
{
char str[20],tmp;
int len,i,j;
clrscr();
printf("n Enter the Char. array...");
scanf("%s",str);
for(len=0;str[len]!='0';len++);
printf("n Entered Char.array is...%s",str);
printf("n Length of entered string is...%dn",len);
for(i=0;i<len;i++)
for(j=i;j<len;j++)
if(str[i]<str[j])
{
tmp=str[i];
str[i]=str[j];
str[j]=tmp;
}
printf("n Sorted Char.array is...%s",str);
getch();
}
C’ software lab - 40 - MCA’05
OUTPUT :
Enter the Char. array...chinagate
Entered Char.array is...chinagate
Length of entered string is...9
Sorted Char.array is...tnihgecaa
C’ software lab - 41 - MCA’05
Experiment No. 12
Date:
AIM : TO PROGRAM TO CHECK THE OCCURRENCE OF A PARTICULAR
NUMBER IN AN ARRAY.
ALGORITHM :
Step 1: Start
Step 2: Declare array a[25], variables n,i,num,count=0 as integer.
Step 3: Store the limit of the array in the variable n.
Step 4: Store the values of the array.
Step 5: Enter the value to be checked and store it in the variable, num.
Step 6: Start a for loop with loop variable, i.Compare each element of the array with
variable num. For each a[i]=num increment the counter count by 1.
Step 7: Display count on the output screen as the number of occurrence.
Step 8: Stop.
C’ software lab - 42 - MCA’05
/*occurance of particular number in an array*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[25],n,num,count=0,temp,flag=0,ch;
clrscr();
do
{
clrscr();
printf("nnEnter number of elements:");
scanf("%d",&n);
printf("nEnter %d array elements:n",n);
for(j=0;j<n;j++)
scanf("%d",&a[j]);
printf("nEnter the number to be searched:");
scanf("%d",&num);
printf("nThe positions of the given number are: ");
for(i=0;i<n;i++)
{
if(a[i]==num)
{
printf("%5d",i+1);
count++; flag=1;
}
}
if(flag==1)
{
printf("nn%d is repeated %d times in the array",num,count);
count = 0;
flag = 0;
}
C’ software lab - 43 - MCA’05
else
printf("0 nnNo element found");
printf("nnnnnttDo you want to continue?(Press 1 to continue):");
scanf("%d",&ch);
}while(ch==1);
getch();
}
C’ software lab - 44 - MCA’05
OUTPUT :
Enter number of elements:5
Enter 5 array elements:
3
5
4
3
6
Enter the number to be searched:3
The positions of the given number are: 1 4
3 is repeated 2 times in the array
Do you want to continue?(Press 1 to continue):1
Enter number of elements:3
Enter 3 array elements:
6
5
23
Enter the number to be searched:8
The positions of the given number are: 0
No element found
Do you want to continue?(Press 1 to continue):1
C’ software lab - 45 - MCA’05
Experiment No. 13
Date:
AIM : TO CHECK WHETHER A GIVEN STRING IS PALINDROME OR NOT
ALGORITHM :
Step 1: Start
Step 2: Initialize a string array a[100],flag=0
Step 3: Calculate length of the string using strlen() function
Step 4: Using for loop from I=0,J=len-1 to j<len/2 perform step 5
Step 5: Check whether A[I] != A[J] if false Set flag=1
Step 6: End for
Step 7: If flag=0 print Palindrome else Not Palindrome
Step 8: Stop
C’ software lab - 46 - MCA’05
/*palindrome*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[10],str1[10];
int i,n,j;
clrscr();
printf("Enter a string:");
scanf("%s",str);
n=strlen(str);
for(i=0,j=n-1;i<n/2;i++,j--)
str[i]=tolower(str[i]);
str[j]=tolower(str[j]);
if(str[i]!=str[j])
{
printf("n String is Not a palindrome") ;
getch();
exit(0);
}
printf("n String is a Palindrome");
getch();
}
C’ software lab - 47 - MCA’05
OUTPUT :
1. Enter a string:INDIAN
String is Not a palindrome
2. Enter a string:Malayalam
String is a Palindrome
C’ software lab - 48 - MCA’05
Experiment No.14
Date:
AIM : TO COUNT THE VOWELS, CONSONANTS AND DIGITS.
ALGORITHM :
Step 1: Start
Step 2: Read str, vowc,conc,I,dig
Step 3: vowc o, conc0,dig0
Step 4: Input the line
Step 5: Print the given line
Step 6: lenlength of the string.
Step 7: Using for loop perform the step 7 to step 10 until len.
Check whether the a[I] is any of a,e,i,o,u if yes
vowcvowc+1 else go to step 8
Step 8: check whether the a[I]is between A and Z.
if yes concconc+1
Step 9: check whether the a[I]is between 0 and 9
If yes digdig+1
Step 10: print the vowc, conc, dig.
Step 11: Stop
C’ software lab - 49 - MCA’05
/*count vowels*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i=0,j;
char a[100],c;
int chr=0,vow=0,dig=0,word=0,whites=0,others=0,cons=0;
clrscr();
printf("Enter a text: ");
scanf("%[^n]",a);
while((c=tolower(a[i++]))!='0')
{
chr++;
if(c== 'a' || c== 'e' || c== 'i'|| c=='o'|| c=='u') vow++;
else if(c >='a' && c<='z') ++cons;
else if(c>='0' && c<='9') ++dig;
else if(c==' ')
{
++word;
++whites;
while((a[i]==' ') || (a[i]=='t'))
{ i++;
whites++;
}
}
}
word++;
printf("n Entered String Consists of :n");
printf("nVowels =%d",vow);
C’ software lab - 50 - MCA’05
printf("nconsonants =%d",cons);
printf("ndigits =%d",dig);
printf("nwords =%d",word);
printf("nwhite spaces =%d",whites);
printf("nothers =%d",others);
printf("nit takes %d bytes for Storage",chr);
getch();
}
C’ software lab - 51 - MCA’05
OUTPUT :
Enter a text: Believe in LOVE
Entered String Consists of :
Vowels =7
consonants =6
digits =0
words =3
white spaces =2
others =0
it takes 15 bytes for Storage
C’ software lab - 52 - MCA’05
Experiment No. 15
Date:
AIM : TO SWAP THE VALUE OF TWO VARIABLES USING POINTERS.
ALGORITHM :
Step1: Start
Step2: Accept two numbers
Step 3: Declare two pointer variables
Step4: Intialise the pointer variable with address of variable
Step5: Use a temporary variable to interchange the address of variable
Step6: Print the Result
Step7: Stop
C’ software lab - 53 - MCA’05
/*Swapping Values Using Pointers*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
void swap(int *,int *);
clrscr();
printf("n Enter the values of A & B :");
scanf("%d%d",&a,&b);
printf("n the values entered are A : %d & B : %d",a,b);
swap(&a,&b);
printf("n the swapped values are A : %d & B : %d",a,b);
getch();
}
void swap(int *x,int *y)
{
int *temp;
*temp=*x;
*x=*y;
*y=*temp;
}
C’ software lab - 54 - MCA’05
OUTPUT :
Enter the values of A & B :1 18
the values entered are A : 1 & B : 18
the swapped values are A : 18 & B : 1
C’ software lab - 55 - MCA’05
Experiment No. 16
Date:
AIM : TO FIND FACTORIAL OF A NUMBER USING RECURSION.
ALGORITHM :
Step1 : Start
Step2 : Declare variables and the function Fact();
Step3 : Accept the values, as num
Step4 : Print outputs as fact(num)
Step5 : In fact check for num to be 1
If true return(1)
If false return(num*fact(num))
Step6 : Stop
C’ software lab - 56 - MCA’05
/*Factorial Using Recursion*/
#include<stdio.h>
#include<conio.h>
void main()
{
int fact(int);
int num;
clrscr();
printf("n Enter the number :");
scanf("%d",&num);
printf("n Factorial of %d is %d",num,fact(num));
getch();
}
int fact(int x)
{
if(x==1)
return(1);
else
return(x*fact(x-1));
}
C’ software lab - 57 - MCA’05
OUTPUT :
Enter the number :6
Factorial of 6 is 720
C’ software lab - 58 - MCA’05
Experiment No.17
Date:
AIM : PROGRAM TO CONVERT NUMBERS INTO DIGITS
ALGORITHM :
Step 1 : Start
Step 2 : Declare separate 2D arrays for representing
characters from : one, two, three, …….,nine.
eleven, twelve, …………, nineteen
ten, twenty, ……………., hundred
Step 3 : Declare variables required
Step 4 : Accept the number less than 10000
Step 5 : Extract the left most digits by modular division of the number by 1000 to a
variable num
a. if num less than 10 give corresponding output
b. if num between eleven and nineteen both inclusive give corresponding
output
c. if number is a multiple of 10 give the result.
d. else split num as one’s and tens’s digit
repeat the step 5.a and 5.c
Step 7 : Add to the output a thousand
Step 8 : Extract the digits in hundreds the number by 1000 to a variable nnum
Step 9 : Extract the left most digits by modular division of the number by 100 to a
variable nunum
a. the number nunum is less than 10, hence give corresponding output
Step 10 : Add to the output a ‘hundred’.
Step 11 : Extract the right most digits by division of the number by 100 to a variable
nunum
a. the number nunum is less than 10, hence give corresponding output
C’ software lab - 59 - MCA’05
b. if num between eleven and nineteen both inclusive give corresponding
output
c. if number is a multiple of 10 give the result.
d. else split num as one’s and tens’s digit
repeat the step 11.a and 11.c
Step 12 : Display the output
Step 13 : Stop
C’ software lab - 60 - MCA’05
/*convert figure into word*/
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
char a[10][10]={"one","two","three","four",
"five","six","seven","eight","nine","ten"};
char b[10][10]={"eleven","twelve","thirteen","fourteen",
"fifiteen","sixteen","seventeen","eighteen",
"nineteen"};
char c[10][10]={"ten","twenty","thirty","forty","fifty",
"sixty","seventy","eighty","ninty","hundred"};
int r,s,t;
long n;
clrscr();
printf("Enter no.");
scanf("%ld",&n);
if(n>9999)
{
r=n/1000;
if(r>10 && r<20)
{
r=r%10;
printf("%s thousand ",b[r-1]);
}
else
{
s=r/10;
t=r%10;
printf("%s",c[s-1]);
printf("%s thousand ",a[t-1]);
C’ software lab - 61 - MCA’05
}
n=n%1000;
}
if(n>1000)
{
r=n/1000;
printf("%s thousand ",a[r-1]);
n=n%1000;
}
if(n>100)
{
r=n/100;
printf("%s hundred ",a[r-1]);
n=n%100;
}
if(n>10 && n<20)
{
r=n%10;
printf("%s ",b[r-1]);
}
if(n>19 && n<=100)
{
r=n/10;
n=n%10;
printf("%s",c[r-1]);
}
if(n>0 && n<=10)
printf("%s ",a[n-1]);
getch();
}
C’ software lab - 62 - MCA’05
OUTPUT :
Enter no.15018
fifiteen thousand eighteen
Enter no.44444
fortyfour thousand four hundred fortyfour
C’ software lab - 63 - MCA’05
Experiment No. 18
Date:
AIM : CONCATENATING TWO STRINGS USING A CHARACTER POINTER.
ALGORITHM :
Step 1: Start
Step 2: Declare 3 character array and 2 character pointer
Step 3: Accept 2 Strings
Step 4: Save the address of the strings to the pointers
Step 5: Save character by character of the first array to new array till the length by
incrementing address
Step 6: Save character by character of the second array by incrementing address of
2nd variable to the resultant array
Step 7: Add a null character at the end of resultant array
Step 8: Print the new array
Step 9: Stop
C’ software lab - 64 - MCA’05
/*String Concatenation using Pointers*/
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#define LEN 10
void main()
{
char *s1,*s2,*s3;
int i=0,j=0;
char c;
clrscr();
s1=(char *)malloc(LEN * sizeof(char));
s2=(char *)malloc(LEN * sizeof(char));
s3=(char *)malloc(LEN * sizeof(char));
printf("n Enter the First String :");
scanf("%s",s1);
printf("n Enter the Second String :");
scanf("%s",s2);
while((c=s1[i])!='0')
{
s3[i]=c;
i++;
}
while((c=s2[j])!='0')
{
s3[i+j]=c;
j++;
} s3[i+j]='0';
printf("n Entered Strings '%s' and '%s' are concatenated to ...%s",s1,s2,s3);
getch();
}
C’ software lab - 65 - MCA’05
OUTPUT :
Enter the First String :Lovingly
Enter the Second String :Your's
Entered Strings 'Lovingly' and 'Your's' are concatenated to ...LovinglyYour's
C’ software lab - 66 - MCA’05
Experiment No. 19
Date:
AIM : TO PROGRAM TO CREATE AND COUNT NUMBER OF CHARACTERS
IN A FILE.
ALGORITHM :
Step 1: start
Step 2: Declare fp as file pointer
Step 3: Declare count=0 as integer and c as character variable.
Step 4: Open the file charcount.txt in write mode (w) as fp.
Step 5: Read characters to be written into the file from the user
Step 6: Write the entered characters into the file using putc( ).
Step 7: close the file charcount.txt and reopen in read mode (r).
Step 8: Read the characters one by one from the file using getc( ) upto EOF and
Increment the count by 1.
Step 9: print the count as number of characters in the file.
Step 10: stop.
C’ software lab - 67 - MCA’05
/*create and count number of charachers in the file*/
#include<stdio.h>
void main()
{
FILE *fp;
char c;
int count =0;
clrscr();
printf("Enter characters:");
fp=fopen("chcount","w");
while((c=getchar())!=EOF)
putc(c,fp);
fclose(fp);
fp=fopen("chcount","r");
printf("String in the file is:");
while((c=getc(fp))!=EOF)
{
printf("%c",c);
++count;
}
fclose(fp);
printf("nNumber of characters in the file is %dn",count);
getch();
}
C’ software lab - 68 - MCA’05
OUTPUT :
Enter characters:Arun is a
goob boy.
^Z
String in the file is:Arun is a
goob boy.
Number of characters in the file is 20
C’ software lab - 69 - MCA’05
Experiment No. 20
Date:
AIM : TO READ A FILE AND WRITE THE ODD VALUE TO A ODDFILE AND
EVEN VALUES TO A EVEN FILE.
ALGORITHM :
Step1: Start
Step2: Declare 3 File pointers (mainfile,oddfile,evenfile)
Step 3: Open the first file in w mode,oddfile and evenfile in write mode
Step4: Write the integer values in the file
Step5: Close the file
Step6: Reopen the file in read mode
Step7: Retrieve the value one by one from the file
Step8: Check whether there is any remainder when divided by two
Step9: If the remainder =0 Write the value to the even file
Step10: Otherwise write the value to the odd file
Step11: Stop
C’ software lab - 70 - MCA’05
/*even and odd file*/
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp1,*fp2,*fp3;
int c,num,n;
clrscr();
fp1=fopen("number","w");
printf("Input numbers:");
while((scanf("%d",&c))!=EOF)
putw(c,fp1);
fclose(fp1);
fp1=fopen("number","r");
fp2=fopen("even","w");
fp3=fopen("odd","w");
printf("nnContents of file 'number':n ");
while((c=getw(fp1))!=EOF)
{
printf("%dt",c);
num=c%2;
if(num==0)
putw(c,fp2);
else
putw(c,fp3);
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
fp2=fopen("even","r");
fp3=fopen("odd","r");
printf("nnContents of file 'even':n ");
C’ software lab - 71 - MCA’05
while((c=getw(fp2))!=EOF)
printf("%dt",c);
printf("nnContents of file 'odd':n ");
while((c=getw(fp3))!=EOF)
printf("%dt",c);
getch();
}
C’ software lab - 72 - MCA’05
OUTPUT :
Input numbers:3
2
4
5
6
7
8
2
1
^Z
Contents of file 'number':
3 2 4 5 6 7 8 2 1
Contents of file 'even':
2 4 6 8 2
Contents of file 'odd':
3 5 7 1
C’ software lab - 73 - MCA’05
C’ software lab - 74 - MCA’05

More Related Content

What's hot

Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c languagetanmaymodi4
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Vishal Patil
 
C formatted and unformatted input and output constructs
C  formatted and unformatted input and output constructsC  formatted and unformatted input and output constructs
C formatted and unformatted input and output constructsGopikaS12
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C LanguageAdnan Khan
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in clavanya marichamy
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple InheritanceBhavyaJain137
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cppAlamgir Hossain
 
Pure virtual function and abstract class
Pure virtual function and abstract classPure virtual function and abstract class
Pure virtual function and abstract classAmit Trivedi
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++HalaiHansaika
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite AutomataRatnakar Mikkili
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator OverloadingNilesh Dalvi
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECSreedhar Chowdam
 
C++ lab assignment
C++ lab assignmentC++ lab assignment
C++ lab assignmentSaket Pathak
 

What's hot (20)

Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
C formatted and unformatted input and output constructs
C  formatted and unformatted input and output constructsC  formatted and unformatted input and output constructs
C formatted and unformatted input and output constructs
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C Language
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Typedef
TypedefTypedef
Typedef
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Pure virtual function and abstract class
Pure virtual function and abstract classPure virtual function and abstract class
Pure virtual function and abstract class
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
File in C language
File in C languageFile in C language
File in C language
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Java operators
Java operatorsJava operators
Java operators
 
C++ lab assignment
C++ lab assignmentC++ lab assignment
C++ lab assignment
 

Similar to C lab-programs

Similar to C lab-programs (20)

C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2
 
Simple C programs
Simple C programsSimple C programs
Simple C programs
 
C++ in 10 Hours.pdf.pdf
C++ in 10 Hours.pdf.pdfC++ in 10 Hours.pdf.pdf
C++ in 10 Hours.pdf.pdf
 
C-LOOP-Session-2.pptx
C-LOOP-Session-2.pptxC-LOOP-Session-2.pptx
C-LOOP-Session-2.pptx
 
Cse 121 presentation on matrix [autosaved]
Cse 121 presentation on matrix [autosaved]Cse 121 presentation on matrix [autosaved]
Cse 121 presentation on matrix [autosaved]
 
25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual
 
Cpl
CplCpl
Cpl
 
C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdf
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
C programs
C programsC programs
C programs
 
c programing
c programingc programing
c programing
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
C language
C languageC language
C language
 
Programming in C Lab
Programming in C LabProgramming in C Lab
Programming in C Lab
 
algorithm
algorithmalgorithm
algorithm
 
Fatima Aliasgher Portfolio
Fatima Aliasgher PortfolioFatima Aliasgher Portfolio
Fatima Aliasgher Portfolio
 
C programming Lab 1
C programming Lab 1C programming Lab 1
C programming Lab 1
 

Recently uploaded

APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

C lab-programs

  • 1. kala Experiment No. 1 Date: AIM: TO FIND SIMPLE INTEREST AND COMPOUND INTEREST ALGORITHM: Step 1: Start Step 2: Declare variables p,r,t,si,ci,amount as float. Step 3: Accept values for p,r,t,n. Step 4: Calculate si=p*t*r/100 Step 5: Calculate amount=p* pow((1+r/n*100),n*t) Step 6: Calculate ci=amount-p Step 7: Print Step 8: Stop C’ software lab - 1 - MCA’05
  • 2. /*Simple interest and compound interest*/ #include<stdio.h> #include<conio.h> #include<math.h> void main() { float p,r,t,si,ci,amount; int n; clrscr(); printf("nEnter principle :"); scanf("%f",&p); printf("nEnter rate :"); scanf("%f",&r); printf("nEnter time :"); scanf("%f",&t); printf("nEnter compoundings per year :"); scanf("%d",&n); si=(p*t*r)/100; printf("nSimple Interest =%7.2f",si); amount=p*pow((double)(1+r/(n*100)),(double)(n*t)); ci=amount-p; printf("nCompond Interest=%7.2fn",ci); getch(); } C’ software lab - 2 - MCA’05
  • 3. OUTPUT : Enter principle :10000 Enter rate :8 Enter time :4 Enter compoundings per year :2 Simple Interest =3200.00 Compond Interest=3685.69 C’ software lab - 3 - MCA’05
  • 4. Experiment No. 2 Date: AIM : TO FIND THE AMSTRONG NUMBER AMONG THE GIVEN NUMBERS ALGORITHM : Step1: Start Step2: Accept a Number Step3: Assign the number to another variable Step4: Check whether the no is greater than Zero go to step 8 Step5: Extract the last digit and add the cube to a sum variable Step6: Divde the number by 10 Step7: Goto step 4 Step8: Check whether the sum = temporary variable and print result Step9: Stop C’ software lab - 4 - MCA’05
  • 5. /*Armstrong number*/ #include<stdio.h> #include<conio.h> void main() { int num,arms=0,tmp,mod; clrscr(); printf("n Enter the number :"); scanf("%d",&num); tmp=num; while(num>0) { mod=num%10; arms+=mod*mod*mod; num=num/10; } if(tmp==arms) printf("n Number %d is armstrong",arms); else printf("n Number %d is not armstrong",tmp); getch(); } C’ software lab - 5 - MCA’05
  • 6. OUTPUT : 1. Enter the number :153 Number 153 is armstrong 2. Enter the number :111 Number 111 is not armstrong C’ software lab - 6 - MCA’05
  • 7. Experiment No. 3 Date: AIM : TO FIND THE ROOTS OF A QUADRATIC EQUATION ALGORITHM : Step1: Start Step2: Accept values for the variables x2 x and constant Step3: Apply the formula b2-4ac (b=cof x2,a=cof x,c=constant) as save to a variable Step4: Check whether the value is less than 0 then print roots are imaginary Step5: If value=0 then print the roots are equal –b/2a Step6: If value greater than 0, 1st root is (-b+sqrt(value))/(2*a), 2nd root is (-b-sqrt(value))/(2*a). Step7: Print the result Step8: Stop C’ software lab - 7 - MCA’05
  • 8. /*Quadratic Equation*/ #include<stdio.h> #include<conio.h> #include<math.h> void main() { float a,b,c,d,r1,r2; clrscr(); printf("n Enter the Coeff. of the Eq. :"); scanf("%f%f%f",&a,&b,&c); d=(b*b)-(4*a*c); if(d==0) { printf("n Roots are REAL and EQUAL"); r1=-b/(2*a); printf("n Root Is : %.2f",r1); } else if (d>0) { printf("n Roots are Real and Distinct"); r1=(-b+sqrt(d))/(2*a); r2=(-b-sqrt(d))/(2*a); printf("n Root 1 : %.2f ..... Root 2 : %.2f",r1,r2); } else { printf("n Roots are imaginary"); } getch(); } C’ software lab - 8 - MCA’05
  • 9. OUTPUT : 1.Enter the Coeff. of the Eq. :1 -5 6 Roots are Real and Distinct Root 1 : 3.00 ..... Root 2 : 2.00 2.Enter the Coeff. of the Eq. :4 4 1 Roots are REAL and EQUAL Root Is : -0.50 C’ software lab - 9 - MCA’05
  • 10. Experiment No. 4 Date: AIM : TO PERFORM MATRICS ADDITION, MULTIPLICATION. TRANSPOSE. ALGORITHM : Step 1: Start Step 2: Declare three integer 2 dimensional array of order 3*3 . Step 3: Accept a choice from user Step 4: If choice = 1 : goto Step 9 Step 5: If choice = 2 : goto Step 10 Step 6: If choice = 3 : goto step 11 Step 7: else if choice = 4 : goto Step 12 Step 8: Accept the elements of the two 2 D arrays Step 9: If choice = 1 a. Add the elements that belong corresponding cells in the arrays and store in third array’s respective cell. b. Display the result. Step 10 : If choice = 2 a. Multiply the elements of the first two matrices and store the result in third array. b. Display the result. Step 11 : If choice = 3 a. Accept the elements of the matrics one. b. Display the matrics in the order column*row format. Step 13 : Repeat step 3 to 11. Step 14 : Stop. C’ software lab - 10 - MCA’05
  • 11. /*Matrics Addition, Multiplication, Transpose*/ #include<stdio.h> #include<conio.h> int a[10][10],b[10][10],c[10][10],r1,r2,c1,c2,i,j,k,ch; void add(); void mul(); void tran(); void accept(int [][10],int,int); void display(int [][10],int,int); void main() { clrscr(); do { clrscr(); printf("n Matrix Manipulator"); printf("n 1.Addition"); printf("n 2.Multiplication"); printf("n 3.Transpose"); printf("n press any other key to exit..."); printf("n Enter U'r choice :"); scanf("%d",&ch); if (ch>=1&&ch<=3) { printf("n Enter order of the matrices :"); printf("n Mat 1 :"); scanf("%d%d",&r1,&c1); printf("n Mat 2 :"); scanf("%d%d",&r2,&c2); } switch(ch) { C’ software lab - 11 - MCA’05
  • 12. case 1: if((r1==r2)&&(c1==c2)) add(); else printf("n addition not possible..."); getch(); break; case 2: if(c1==r2) mul(); else printf("n multiplication not possible..."); getch(); break; case 3: tran();getch();break; default: printf("n Wrong choice Exit..."); } }while(ch>0&&ch<4); getch(); } void add() { printf("n Matrics addition"); printf("n Enter Matrics 1:"); accept(a,r1,c1); printf("n Enter Matrics 2:"); accept(b,r2,c2); for(i=0;i<r1;i++) for(j=0;j<c1;j++) c[i][j]= a[i][j]+b[i][j]; printf("n Matrics A :n"); C’ software lab - 12 - MCA’05
  • 13. display(a,r1,c1); printf("n Matrics B :n"); display(b,r2,c2); printf("n Matrics C :n"); display(c,r1,c2); } void mul() { printf("n Matrics multiplication"); printf("n Enter Matrics 1:"); accept(a,r1,c1); printf("n Enter Matrics 2:"); accept(b,r2,c2); for(i=0;i<r1;i++) for(j=0;j<c2;j++) { c[i][j]=0; for(k=0;k<c1;k++) c[i][j] += a[i][k]*b[k][j]; } printf("n Matrics A :n"); display(a,r1,c1); printf("n Matrics B :n"); display(b,r2,c2); printf("n Matrics C :n"); display(c,r1,c2); } void tran() { printf("n Matrics Transpose"); C’ software lab - 13 - MCA’05
  • 14. printf("n Enter Matrics :n"); accept(a,r1,c1); display(a,r1,c1); printf("n Transposed Matrics :n"); for(i=0;i<r1;i++) { for(j=0;j<c1;j++) { printf("%dt",a[j][i]); } printf("n"); } } void display(int x[][10],int m,int n) { for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%dt",x[i][j]); } printf("n"); } } void accept(int x[][10],int m,int n) { for(i=0;i<m;i++) { for(j=0;j<n;j++) { C’ software lab - 14 - MCA’05
  • 16. OUTPUT : Matrix Manipulator 1.Addition 2.Multiplication 3.Transpose press any other key to exit... Enter U'r choice :3 Enter order of the matrices : Mat 1 :3 3 Mat 2 :2 2 Matrics Transpose Enter Matrics : 1 2 3 2 3 4 3 4 5 1 2 3 2 3 4 3 4 5 Transposed Matrics : 1 2 3 2 3 4 3 4 5 C’ software lab - 16 - MCA’05
  • 17. Experiment No. 5 Date: AIM : TO FIND OUT REVERSE OF A GIVEN NUMBER ALGORITHM : Step 1: Start Step 2: Declare variables n, dig, rev=0 as integer. Step 3: Input the number, n. Step 4: If n>0 then goto step 5 else goto step 8 Step 5: Modular division is done on the number with 10 .The value obtained is assigned to variable Step 6: The variable, rev is multiplied by 10 and then added with the variable dig, thisvalue is assigned to rev. Step 7: The variable, n is divided by 10 and the result is stored in n. Goto step 4 Step 8: The result is displayed on the screen Step 9: Stop C’ software lab - 17 - MCA’05
  • 18. /*Reverse of a Number*/ #include<stdio.h> #include<conio.h> void main() { int num,rnum=0,mod; clrscr(); printf("n Enter the Number :"); scanf("%d",&num); while(num>0) { mod=num%10; rnum=rnum*10+mod; num=num/10; } printf("n reverse of number is %d",rnum); getch(); } C’ software lab - 18 - MCA’05
  • 19. OUTPUT : Enter the Number :1234 reverse of number is 4321 C’ software lab - 19 - MCA’05
  • 20. Experiment No. 6 Date: AIM : PERFORM SORTING A ONE DIMENSIONAL ALGORITHM : Step 1 : Start Step 2 : Read the limit, N Step 3 : Read elements of A[N] using for loop Step 4 : Using for loop check whether A[I]>A[J] if yes then proceed Step 5 : tA[I] Step 6 : A[I]A[J] Step 7 : A[J]t Step 8 : End If Step 9 : End for Step 10 : Print Sorted array A[N] Step 11 : Stop C’ software lab - 20 - MCA’05
  • 21. /*Sorting a 1-D array*/ #include<stdio.h> #include<conio.h> void main() { int a[15],i,tmp,j,k; clrscr(); printf("n Enter the Size :"); scanf("%i",&i); printf("n Enter the elements in the array : n"); for(j=0;j<i;j++) { scanf("%d",&a[j]); } printf("n Entered Elements are : n"); for(j=0;j<i;j++) { printf("%dt",a[j]); } for(j=0;j<i;j++) { for(k=j;k<i;k++) { if(a[j]>a[k]) { tmp = a[j]; a[j]= a[k]; a[k]=tmp; } } } printf("n Sorted Elements are : n"); C’ software lab - 21 - MCA’05
  • 23. OUTPUT : Enter the Size :8 Enter the elements in the array : 3 7 5 9 7 4 3 8 Entered Elements are : 3 7 5 9 7 4 3 8 Sorted Elements are : 3 3 4 5 7 7 8 9 C’ software lab - 23 - MCA’05
  • 24. Experiment No. 7 Date: AIM : TO PROGRAM FOR SORT THE ENTERED STRINGS IN ALPHABETIC ORDER. ALGORITHM : Step 1: Start Step 2: Accept a single dimensional array, also declare another temporary array Step 3: Sort the elements of the vector in ascending order Step 4: Extract numbers one by one from main vector and check whether the number is equal to the previous number if no’s are different insert it into the temporary array. step 5: Print the temporary Array to see the result step 6: Stop C’ software lab - 24 - MCA’05
  • 25. /*Deleting Duplicates in a 1-D array*/ #include<stdio.h> #include<conio.h> void main() { int a[15],i,tmp,j,k; clrscr(); printf("n Enter the Size :"); scanf("%i",&i); printf("n Enter the elements in the array : n"); for(j=0;j<i;j++) { scanf("%d",&a[j]); } printf("n Entered Elements are : n"); for(j=0;j<i;j++) { printf("%dt",a[j]); } for(j=0;j<i;j++) { for(k=j;k<i;k++) { if(a[j]>a[k]) { tmp = a[j]; a[j]= a[k]; a[k]=tmp; } } } for(j=0;j<i;j++) C’ software lab - 25 - MCA’05
  • 26. { if(a[j]==a[j+1]) { for(k=j;k<i;k++) { a[k]=a[k+1]; } i--;j--; } } printf("n Sorted Elements are : n"); for(j=0;j<i;j++) { printf("%dt",a[j]); } getch(); } C’ software lab - 26 - MCA’05
  • 27. OUTPUT : Enter the Size :8 Enter the elements in the array : 6 5 8 4 2 6 8 5 Entered Elements are : 6 5 8 4 2 6 8 5 Sorted Elements are : 2 4 5 6 8 C’ software lab - 27 - MCA’05
  • 28. Experiment No. 8 Date: AIM : WRITE A PROGRAM TO PRINT FIBONACCI SERIES. ALGORITHM : Step 1: Start Step 2: Declare variables n,a=0,b=1,c,i=1 as integer. Step 3: Input value of n. Step 4: Value of n is decremented by 1. Step 5: The sum of a and b is assigned to c. Step 6: The value c is displayed. Step 7: The value of b is assigned to a and value of c is assigned to b. Step 8: value of i is incremented by 1 Step 9: If i<n then goto step 6 Else goto step 10. Step 10: Stop. C’ software lab - 28 - MCA’05
  • 29. /*Fibonacci Series*/ #include<stdio.h> #include<conio.h> void main() { int f=1,s=0,t,r,i; clrscr(); printf("n Enter the range :"); scanf("%d",&t); printf("n Fibonacci Series...in %d numbers is...",t); printf("n%d ",s); for(i=0;i<t-1;i++) { r=f+s; f=s; s=r; printf(" %d ",r); } getch(); } C’ software lab - 29 - MCA’05
  • 30. OUTPUT : Enter the range :8 Fibonacci Series...in 8 numbers is... 0 1 1 2 3 5 8 13 C’ software lab - 30 - MCA’05
  • 31. Experiment No. 9 Date : AIM : TO PERFORM THE FUNCTIONS OF A CALCULATOR USING SWITCH CASE AND FUNCTIONS. ALGORITHM : Step 1 : Start Step 2 : Read choice 1.Add 2.Sub 3.Mul 4.Div. Step 3 : If choice =1 then add the numbers Step 4 : If choice =2 then subtract the numbers. Step 5 : If choice = 3 then multiply the numbers. Step 6 : If choice = 4 then divide the numbers Step 7 : Display respective output. Step 8 : Stop C’ software lab - 31 - MCA’05
  • 32. /*Calculator*/ #include<stdio.h> #include<conio.h> #include<string.h> void main() { int a,b; int ch; do { clrscr(); printf("nnnnnnn"); printf("ttttCALCULATORnnnn"); printf("ttt1.Additionn"); printf("ttt2.Substractionn"); printf("ttt3.Multiplicationn"); printf("ttt4.Divisionn"); printf("ttt5.Exit"); printf("nnntttEnter U'r choice :"); scanf("%d",&ch); if(ch<5) { printf("ntttEnter two values:"); scanf("%d %d",&a,&b); } else exit(0); switch(ch) { case 1: printf("tttThe sum is :%d",a+b); getch();break; case 2: printf("tttThe diference is :%d",a-b);getch();break; case 3: C’ software lab - 32 - MCA’05
  • 33. printf("tttThe multiplication is :%d",a*b);getch();break; case 4: if(b==0) printf("tttDivide by zero error"); else printf("tttTHe division is :%d",a/b);getch(); break; case 5: exit(0); } }while(ch<6); getch(); } C’ software lab - 33 - MCA’05
  • 34. OUTPUT : CALCULATOR 1.Addition 2.Substraction 3.Multiplication 4.Division 5.Exit Enter U'r choice :1 Enter two values:1 18 The sum is :19 CALCULATOR 1.Addition 2.Substraction 3.Multiplication 4.Division 5.Exit Enter U'r choice :4 Enter two values:18 1 THe division is :18 C’ software lab - 34 - MCA’05
  • 35. Experiment No.10 Date: AIM : TO WRITE A PROGRAM TO CREATE AND MANIPULATE STUDENTS RECORD USING STRUCTURES AND POINTERS. ALGORITHM : Step 1 : Start Step 2 : Declare structure Stud Roll_no as Integer Name as Character array Grade as Character Mark, as an integer array Step 3 : Create student object as an array as st[10], and also a pointer object *sd Step 4 : Declare tot_mark, n Step 5 : Accept number of entries as n Step 6 : Accept student details Step 7 : Calculate the average of students as sum of marks / 3 Step 8 : Calculate the grades and store to structure as on the conditions if average > = 80 : grade = A if average > = 60 and average < 80 : grade = B if average > = 50 and average < 60 : grade = c else if average < 50 : grade = Failed Step 9 : Print details of students as per fields in the structure Step 10 : Stop C’ software lab - 35 - MCA’05
  • 36. /*Student’s Record Using Poinetrs*/ #include<stdio.h> #include<conio.h> struct stud { int regno; char name[20]; int mark[3]; char grade; }s[10],*st; void main() { int i,avg=0,j,num; clrscr(); printf("n Enter the number of students..."); scanf("%d",&num); st = s; for(i=0;i<num;i++) { printf("n Enter student's Details :"); printf("n Roll no :"); scanf("%d",&st->regno); printf(" Name :"); scanf("%s",st->name); for(j=0;j<3;j++) { printf(" mark %d :",j+1); scanf("%d",&st->mark[j]); avg+=st->mark[j]; } printf("Average of %s is %d",st->name,avg=avg/3); C’ software lab - 36 - MCA’05
  • 37. if(avg>=80) st->grade='A'; else if(avg>=60 && avg<80) st->grade='B'; else if(avg>=50 && avg<60) st->grade='C'; else st->grade='F'; st++; avg=0; } st=s; printf("n Student details..."); printf("nReg_notNamettMarkst1t2t3tgrade"); for(i=0;i<num;i++) { printf("n%dt%sttt%dt%dt%dt%c",st->regno,st->name,st->mark[0],st- >mark[1],st->mark[2],st->grade); st++; } getch(); } C’ software lab - 37 - MCA’05
  • 38. OUTPUT : Enter the number of students...2 Enter student's Details : Roll no :1 Name :Sachin mark 1 :75 mark 2 :85 mark 3 :80 Average of Sachin is 80 Enter student's Details : Roll no :2 Name :Rohit mark 1 :80 mark 2 :65 mark 3 :82 Average of Rohit is 75 Student details... Reg_no Name Marks 1 2 3 grade 1 Sachin 75 85 80 A 2 Rohit 80 65 82 B C’ software lab - 38 - MCA’05
  • 39. Experiment No. 11 Date: AIM : TO PERFORM, SORT A CHARACTER ARRAY IN ACSENDING ORDER ALGORITHM : Step 1: Start Step 2: Accept a character array Step 3: use a for loop to extract characters from the array and check it with each characters of the array if value is greater interchange the value in the positon Step 4: Display the result Step 5: Stop C’ software lab - 39 - MCA’05
  • 40. /*Sorting a 1-D Charater array*/ #include<stdio.h> #include<conio.h> void main() { char str[20],tmp; int len,i,j; clrscr(); printf("n Enter the Char. array..."); scanf("%s",str); for(len=0;str[len]!='0';len++); printf("n Entered Char.array is...%s",str); printf("n Length of entered string is...%dn",len); for(i=0;i<len;i++) for(j=i;j<len;j++) if(str[i]<str[j]) { tmp=str[i]; str[i]=str[j]; str[j]=tmp; } printf("n Sorted Char.array is...%s",str); getch(); } C’ software lab - 40 - MCA’05
  • 41. OUTPUT : Enter the Char. array...chinagate Entered Char.array is...chinagate Length of entered string is...9 Sorted Char.array is...tnihgecaa C’ software lab - 41 - MCA’05
  • 42. Experiment No. 12 Date: AIM : TO PROGRAM TO CHECK THE OCCURRENCE OF A PARTICULAR NUMBER IN AN ARRAY. ALGORITHM : Step 1: Start Step 2: Declare array a[25], variables n,i,num,count=0 as integer. Step 3: Store the limit of the array in the variable n. Step 4: Store the values of the array. Step 5: Enter the value to be checked and store it in the variable, num. Step 6: Start a for loop with loop variable, i.Compare each element of the array with variable num. For each a[i]=num increment the counter count by 1. Step 7: Display count on the output screen as the number of occurrence. Step 8: Stop. C’ software lab - 42 - MCA’05
  • 43. /*occurance of particular number in an array*/ #include<stdio.h> #include<conio.h> void main() { int i,j,a[25],n,num,count=0,temp,flag=0,ch; clrscr(); do { clrscr(); printf("nnEnter number of elements:"); scanf("%d",&n); printf("nEnter %d array elements:n",n); for(j=0;j<n;j++) scanf("%d",&a[j]); printf("nEnter the number to be searched:"); scanf("%d",&num); printf("nThe positions of the given number are: "); for(i=0;i<n;i++) { if(a[i]==num) { printf("%5d",i+1); count++; flag=1; } } if(flag==1) { printf("nn%d is repeated %d times in the array",num,count); count = 0; flag = 0; } C’ software lab - 43 - MCA’05
  • 44. else printf("0 nnNo element found"); printf("nnnnnttDo you want to continue?(Press 1 to continue):"); scanf("%d",&ch); }while(ch==1); getch(); } C’ software lab - 44 - MCA’05
  • 45. OUTPUT : Enter number of elements:5 Enter 5 array elements: 3 5 4 3 6 Enter the number to be searched:3 The positions of the given number are: 1 4 3 is repeated 2 times in the array Do you want to continue?(Press 1 to continue):1 Enter number of elements:3 Enter 3 array elements: 6 5 23 Enter the number to be searched:8 The positions of the given number are: 0 No element found Do you want to continue?(Press 1 to continue):1 C’ software lab - 45 - MCA’05
  • 46. Experiment No. 13 Date: AIM : TO CHECK WHETHER A GIVEN STRING IS PALINDROME OR NOT ALGORITHM : Step 1: Start Step 2: Initialize a string array a[100],flag=0 Step 3: Calculate length of the string using strlen() function Step 4: Using for loop from I=0,J=len-1 to j<len/2 perform step 5 Step 5: Check whether A[I] != A[J] if false Set flag=1 Step 6: End for Step 7: If flag=0 print Palindrome else Not Palindrome Step 8: Stop C’ software lab - 46 - MCA’05
  • 47. /*palindrome*/ #include<stdio.h> #include<conio.h> #include<string.h> void main() { char str[10],str1[10]; int i,n,j; clrscr(); printf("Enter a string:"); scanf("%s",str); n=strlen(str); for(i=0,j=n-1;i<n/2;i++,j--) str[i]=tolower(str[i]); str[j]=tolower(str[j]); if(str[i]!=str[j]) { printf("n String is Not a palindrome") ; getch(); exit(0); } printf("n String is a Palindrome"); getch(); } C’ software lab - 47 - MCA’05
  • 48. OUTPUT : 1. Enter a string:INDIAN String is Not a palindrome 2. Enter a string:Malayalam String is a Palindrome C’ software lab - 48 - MCA’05
  • 49. Experiment No.14 Date: AIM : TO COUNT THE VOWELS, CONSONANTS AND DIGITS. ALGORITHM : Step 1: Start Step 2: Read str, vowc,conc,I,dig Step 3: vowc o, conc0,dig0 Step 4: Input the line Step 5: Print the given line Step 6: lenlength of the string. Step 7: Using for loop perform the step 7 to step 10 until len. Check whether the a[I] is any of a,e,i,o,u if yes vowcvowc+1 else go to step 8 Step 8: check whether the a[I]is between A and Z. if yes concconc+1 Step 9: check whether the a[I]is between 0 and 9 If yes digdig+1 Step 10: print the vowc, conc, dig. Step 11: Stop C’ software lab - 49 - MCA’05
  • 50. /*count vowels*/ #include<stdio.h> #include<conio.h> #include<string.h> void main() { int i=0,j; char a[100],c; int chr=0,vow=0,dig=0,word=0,whites=0,others=0,cons=0; clrscr(); printf("Enter a text: "); scanf("%[^n]",a); while((c=tolower(a[i++]))!='0') { chr++; if(c== 'a' || c== 'e' || c== 'i'|| c=='o'|| c=='u') vow++; else if(c >='a' && c<='z') ++cons; else if(c>='0' && c<='9') ++dig; else if(c==' ') { ++word; ++whites; while((a[i]==' ') || (a[i]=='t')) { i++; whites++; } } } word++; printf("n Entered String Consists of :n"); printf("nVowels =%d",vow); C’ software lab - 50 - MCA’05
  • 51. printf("nconsonants =%d",cons); printf("ndigits =%d",dig); printf("nwords =%d",word); printf("nwhite spaces =%d",whites); printf("nothers =%d",others); printf("nit takes %d bytes for Storage",chr); getch(); } C’ software lab - 51 - MCA’05
  • 52. OUTPUT : Enter a text: Believe in LOVE Entered String Consists of : Vowels =7 consonants =6 digits =0 words =3 white spaces =2 others =0 it takes 15 bytes for Storage C’ software lab - 52 - MCA’05
  • 53. Experiment No. 15 Date: AIM : TO SWAP THE VALUE OF TWO VARIABLES USING POINTERS. ALGORITHM : Step1: Start Step2: Accept two numbers Step 3: Declare two pointer variables Step4: Intialise the pointer variable with address of variable Step5: Use a temporary variable to interchange the address of variable Step6: Print the Result Step7: Stop C’ software lab - 53 - MCA’05
  • 54. /*Swapping Values Using Pointers*/ #include<stdio.h> #include<conio.h> void main() { int a,b; void swap(int *,int *); clrscr(); printf("n Enter the values of A & B :"); scanf("%d%d",&a,&b); printf("n the values entered are A : %d & B : %d",a,b); swap(&a,&b); printf("n the swapped values are A : %d & B : %d",a,b); getch(); } void swap(int *x,int *y) { int *temp; *temp=*x; *x=*y; *y=*temp; } C’ software lab - 54 - MCA’05
  • 55. OUTPUT : Enter the values of A & B :1 18 the values entered are A : 1 & B : 18 the swapped values are A : 18 & B : 1 C’ software lab - 55 - MCA’05
  • 56. Experiment No. 16 Date: AIM : TO FIND FACTORIAL OF A NUMBER USING RECURSION. ALGORITHM : Step1 : Start Step2 : Declare variables and the function Fact(); Step3 : Accept the values, as num Step4 : Print outputs as fact(num) Step5 : In fact check for num to be 1 If true return(1) If false return(num*fact(num)) Step6 : Stop C’ software lab - 56 - MCA’05
  • 57. /*Factorial Using Recursion*/ #include<stdio.h> #include<conio.h> void main() { int fact(int); int num; clrscr(); printf("n Enter the number :"); scanf("%d",&num); printf("n Factorial of %d is %d",num,fact(num)); getch(); } int fact(int x) { if(x==1) return(1); else return(x*fact(x-1)); } C’ software lab - 57 - MCA’05
  • 58. OUTPUT : Enter the number :6 Factorial of 6 is 720 C’ software lab - 58 - MCA’05
  • 59. Experiment No.17 Date: AIM : PROGRAM TO CONVERT NUMBERS INTO DIGITS ALGORITHM : Step 1 : Start Step 2 : Declare separate 2D arrays for representing characters from : one, two, three, …….,nine. eleven, twelve, …………, nineteen ten, twenty, ……………., hundred Step 3 : Declare variables required Step 4 : Accept the number less than 10000 Step 5 : Extract the left most digits by modular division of the number by 1000 to a variable num a. if num less than 10 give corresponding output b. if num between eleven and nineteen both inclusive give corresponding output c. if number is a multiple of 10 give the result. d. else split num as one’s and tens’s digit repeat the step 5.a and 5.c Step 7 : Add to the output a thousand Step 8 : Extract the digits in hundreds the number by 1000 to a variable nnum Step 9 : Extract the left most digits by modular division of the number by 100 to a variable nunum a. the number nunum is less than 10, hence give corresponding output Step 10 : Add to the output a ‘hundred’. Step 11 : Extract the right most digits by division of the number by 100 to a variable nunum a. the number nunum is less than 10, hence give corresponding output C’ software lab - 59 - MCA’05
  • 60. b. if num between eleven and nineteen both inclusive give corresponding output c. if number is a multiple of 10 give the result. d. else split num as one’s and tens’s digit repeat the step 11.a and 11.c Step 12 : Display the output Step 13 : Stop C’ software lab - 60 - MCA’05
  • 61. /*convert figure into word*/ #include<stdio.h> #include<string.h> #include<conio.h> void main() { char a[10][10]={"one","two","three","four", "five","six","seven","eight","nine","ten"}; char b[10][10]={"eleven","twelve","thirteen","fourteen", "fifiteen","sixteen","seventeen","eighteen", "nineteen"}; char c[10][10]={"ten","twenty","thirty","forty","fifty", "sixty","seventy","eighty","ninty","hundred"}; int r,s,t; long n; clrscr(); printf("Enter no."); scanf("%ld",&n); if(n>9999) { r=n/1000; if(r>10 && r<20) { r=r%10; printf("%s thousand ",b[r-1]); } else { s=r/10; t=r%10; printf("%s",c[s-1]); printf("%s thousand ",a[t-1]); C’ software lab - 61 - MCA’05
  • 62. } n=n%1000; } if(n>1000) { r=n/1000; printf("%s thousand ",a[r-1]); n=n%1000; } if(n>100) { r=n/100; printf("%s hundred ",a[r-1]); n=n%100; } if(n>10 && n<20) { r=n%10; printf("%s ",b[r-1]); } if(n>19 && n<=100) { r=n/10; n=n%10; printf("%s",c[r-1]); } if(n>0 && n<=10) printf("%s ",a[n-1]); getch(); } C’ software lab - 62 - MCA’05
  • 63. OUTPUT : Enter no.15018 fifiteen thousand eighteen Enter no.44444 fortyfour thousand four hundred fortyfour C’ software lab - 63 - MCA’05
  • 64. Experiment No. 18 Date: AIM : CONCATENATING TWO STRINGS USING A CHARACTER POINTER. ALGORITHM : Step 1: Start Step 2: Declare 3 character array and 2 character pointer Step 3: Accept 2 Strings Step 4: Save the address of the strings to the pointers Step 5: Save character by character of the first array to new array till the length by incrementing address Step 6: Save character by character of the second array by incrementing address of 2nd variable to the resultant array Step 7: Add a null character at the end of resultant array Step 8: Print the new array Step 9: Stop C’ software lab - 64 - MCA’05
  • 65. /*String Concatenation using Pointers*/ #include<stdio.h> #include<conio.h> #include<malloc.h> #define LEN 10 void main() { char *s1,*s2,*s3; int i=0,j=0; char c; clrscr(); s1=(char *)malloc(LEN * sizeof(char)); s2=(char *)malloc(LEN * sizeof(char)); s3=(char *)malloc(LEN * sizeof(char)); printf("n Enter the First String :"); scanf("%s",s1); printf("n Enter the Second String :"); scanf("%s",s2); while((c=s1[i])!='0') { s3[i]=c; i++; } while((c=s2[j])!='0') { s3[i+j]=c; j++; } s3[i+j]='0'; printf("n Entered Strings '%s' and '%s' are concatenated to ...%s",s1,s2,s3); getch(); } C’ software lab - 65 - MCA’05
  • 66. OUTPUT : Enter the First String :Lovingly Enter the Second String :Your's Entered Strings 'Lovingly' and 'Your's' are concatenated to ...LovinglyYour's C’ software lab - 66 - MCA’05
  • 67. Experiment No. 19 Date: AIM : TO PROGRAM TO CREATE AND COUNT NUMBER OF CHARACTERS IN A FILE. ALGORITHM : Step 1: start Step 2: Declare fp as file pointer Step 3: Declare count=0 as integer and c as character variable. Step 4: Open the file charcount.txt in write mode (w) as fp. Step 5: Read characters to be written into the file from the user Step 6: Write the entered characters into the file using putc( ). Step 7: close the file charcount.txt and reopen in read mode (r). Step 8: Read the characters one by one from the file using getc( ) upto EOF and Increment the count by 1. Step 9: print the count as number of characters in the file. Step 10: stop. C’ software lab - 67 - MCA’05
  • 68. /*create and count number of charachers in the file*/ #include<stdio.h> void main() { FILE *fp; char c; int count =0; clrscr(); printf("Enter characters:"); fp=fopen("chcount","w"); while((c=getchar())!=EOF) putc(c,fp); fclose(fp); fp=fopen("chcount","r"); printf("String in the file is:"); while((c=getc(fp))!=EOF) { printf("%c",c); ++count; } fclose(fp); printf("nNumber of characters in the file is %dn",count); getch(); } C’ software lab - 68 - MCA’05
  • 69. OUTPUT : Enter characters:Arun is a goob boy. ^Z String in the file is:Arun is a goob boy. Number of characters in the file is 20 C’ software lab - 69 - MCA’05
  • 70. Experiment No. 20 Date: AIM : TO READ A FILE AND WRITE THE ODD VALUE TO A ODDFILE AND EVEN VALUES TO A EVEN FILE. ALGORITHM : Step1: Start Step2: Declare 3 File pointers (mainfile,oddfile,evenfile) Step 3: Open the first file in w mode,oddfile and evenfile in write mode Step4: Write the integer values in the file Step5: Close the file Step6: Reopen the file in read mode Step7: Retrieve the value one by one from the file Step8: Check whether there is any remainder when divided by two Step9: If the remainder =0 Write the value to the even file Step10: Otherwise write the value to the odd file Step11: Stop C’ software lab - 70 - MCA’05
  • 71. /*even and odd file*/ #include<stdio.h> #include<conio.h> void main() { FILE *fp1,*fp2,*fp3; int c,num,n; clrscr(); fp1=fopen("number","w"); printf("Input numbers:"); while((scanf("%d",&c))!=EOF) putw(c,fp1); fclose(fp1); fp1=fopen("number","r"); fp2=fopen("even","w"); fp3=fopen("odd","w"); printf("nnContents of file 'number':n "); while((c=getw(fp1))!=EOF) { printf("%dt",c); num=c%2; if(num==0) putw(c,fp2); else putw(c,fp3); } fclose(fp1); fclose(fp2); fclose(fp3); fp2=fopen("even","r"); fp3=fopen("odd","r"); printf("nnContents of file 'even':n "); C’ software lab - 71 - MCA’05
  • 72. while((c=getw(fp2))!=EOF) printf("%dt",c); printf("nnContents of file 'odd':n "); while((c=getw(fp3))!=EOF) printf("%dt",c); getch(); } C’ software lab - 72 - MCA’05
  • 73. OUTPUT : Input numbers:3 2 4 5 6 7 8 2 1 ^Z Contents of file 'number': 3 2 4 5 6 7 8 2 1 Contents of file 'even': 2 4 6 8 2 Contents of file 'odd': 3 5 7 1 C’ software lab - 73 - MCA’05
  • 74. C’ software lab - 74 - MCA’05