0% found this document useful (0 votes)
4 views9 pages

Labmanual5 1

Uploaded by

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

Labmanual5 1

Uploaded by

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

/********************************************************

Name :
Class : 1 BCA
Reg no :
PART B-5 Program to read a string and count number of letters, digits,
vowels, consonants, spaces and special characters present in it using user
defined function.
********************************************************** */
#include<stdio.h>
#include<conio.h>
int isVowel(char c);
int isConsonant(char c);
int isDigit(char c);
int isWhitespace(char c);
int isSpecial(char c);
void main()
{
char str[500];
int V = 0, C = 0, D = 0, W = 0,S=0,M=0,i;
clrscr();
printf("Enter a string\n");
gets(str);
for(i = 0;str[i] != '\0'; i++)
{
V += isVowel(str[i]);
C += isConsonant(str[i]);
D += isDigit(str[i]);
W += isWhitespace(str[i]);
S += isSpecial(str[i]);
M += isWhitespace(str[i]);

}
printf("Vowels: %d\n",V);
printf("Consonants: %d\n",C);
printf("Digits: %d\n",D);
printf("White spaces: %d\n",W);
printf("Total letters:%d\n",S);
printf("Special character:%d",M);
Mr K Praveen Kumar, SMC, SHIRVA P a g e 20 | 28
getch();
}

int isVowel(char c)
{

if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='A'||c=='E'||c=='I'||c=
='O'||c=='U')
{
return 1;
}
else
{
return 0;
}
}

int isConsonant(char c)
{
if(((c>='a'&& c<='z') || (c>='A'&& c<='Z')) && !isVowel(c))
{
return 1;
}
else
{
return 0;
}
}
int isDigit(char c)
{
if(c>='0'&&c<='9')
{
return 1;
}
else
{
return 0;
}
Mr K Praveen Kumar, SMC, SHIRVA P a g e 21 | 28
}
int isWhitespace(char c)
{
if(c == ' ')
{
return 1;
}
else
{
return 0;
}
}
int isSpecial(char c)

{
if(c==' ')
{
return 0;
}
else
{
return 1;
}
}
Output:
Enter a string
Smc 123 shirva @@@ BCA’s
Vowels:3
Consonants:10
Digits:3
White spaces:4
Total letters:20
Special character:4

Mr K Praveen Kumar, SMC, SHIRVA P a g e 22 | 28


/*************************************************************************
PARTB- 6 Program sort a list of strings in ascending order using Pointers
*************************************************************************/
#include<stdio.h>
#include<conio.h>
void main()
{
char *T;
int I,J,K,n;
char *ARRAY[100];
clrscr();
printf("Enter how many strings you want\n");
scanf("%d",&n);
for(I=0;I<n;I++)
{
printf("enter %d string\n",I+1);
ARRAY[I]=(char *)malloc(20*sizeof(char));
scanf("%s",ARRAY[I]);
}
printf("Entered strings are\n");
for(I=0;I<n;I++)
{
printf("%s\t",ARRAY[I]);
}
printf("\n sorted list are \n");
for(I=0;I<n;I++)
{
for(J=0;J<n-I;J++)
{
K=strcmp(ARRAY[J],ARRAY[J+1]);
if(K>0)
{
T=ARRAY[J];
ARRAY[J]=ARRAY[J+1];
ARRAY[J+1]=T;
}
}
}
Mr K Praveen Kumar, SMC, SHIRVA P a g e 23 | 28
for(I=0;I<5;I++)
{
printf("%s \t",ARRAY[I]);
}
getch();
}
OUTPUT:

/********************************************************
PARTB- 7 Program to enter the information of a student like name, register
number, marks in three subjects into a structure and display total,
average and grade Display details in a neat form.
********************************************************** */
#include<stdio.h>
#include<conio.h>
struct student
{
int regno;
char name[10];
int m1;
int m2;
int m3;
};
Mr K Praveen Kumar, SMC, SHIRVA P a g e 24 | 28
void main()
{
struct student s[10];
int n,i,total;
float avg;
clrscr();
printf("**********OUTPUT**********");
printf("\nEnter the number of students:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter the regno :");
scanf("%d",&s[i].regno);
fflush(stdin);
printf("\nEnter the student name:");
gets(s[i].name);
printf("\nEnter the marks in 3 subjects:");
scanf("%d %d %d",&s[i].m1,&s[i].m2,&s[i].m3);
printf("\n...............................\n");
}
printf("\nRNO\tNAME\tM1\tM2\tM3\tTOTAL\tAVERAGE\t\tGRA
DE\n ");
for(i=0;i<n;i++)
{
total=s[i].m1+s[i].m2+s[i].m3;
avg=(total/3.0);
printf("%d\t",s[i].regno);
printf("%s\t",s[i].name);
printf("%d\t %d\t %d\t %d \t %f\t",
s[i].m1,s[i].m2,s[i].m3,total,avg);
if(s[i].m1<35||s[i].m2<35||s[i].m3<35)
{
printf("fail");
}
else if(avg>=70)
{
printf("distinction");
}
Mr K Praveen Kumar, SMC, SHIRVA P a g e 25 | 28
else if(avg>=60)
{
printf("first class");
}
else if(avg>=50)
{
printf("second class");
}
else {
printf("third class");
}
printf("\n");
}
getch();
}
Output:
Enter the number of students:2
enter the regno :1
Enter the student name:naveen
Enter the marks in 3 subjects:
85 85 85
...............................
enter the regno :2
Enter the student name:sudeep
Enter the marks in 3 subjects:
45 25 35
RNO NAME M1 M2 M3 TOTAL AVERAGE GRADE
1 naveen 85 85 85 255 85.000000 distinction
2 sudeep 45 25 35 105 35.000000 fail

Mr K Praveen Kumar, SMC, SHIRVA P a g e 26 | 28


/***********************************************************************************
PARTB- 8 Program to input Name of the branches, Total sales of company
into an array of structures. Display branch details in a tabular format.
Also display the branch name that recorded the highest sales.
*********************************************************************************/
#include<stdio.h>
#include<conio.h>
struct cominfo
{
char bname[10];
int sales;
};
void main()
{
struct cominfo com[10],max;
// declaring structure and array of structure variable
int n,i;
clrscr();
printf("***********output***********\n");
printf("Enter the number of branches:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
fflush(stdin);
printf("Enter branch name:\n");
gets(com[i].bname);
printf("Enter total sales:\n");
scanf("%d",&com[i].sales);
}
max=com[0];
for(i=1;i<n;i++)
{
if(com[i].sales>max.sales)
max=com[i];
}
printf("BRANCH\tTOTAL SALES\n");
printf("--------------------------------\n");
for(i=0;i<n;i++)
Mr K Praveen Kumar, SMC, SHIRVA P a g e 27 | 28
{
printf("%s\t%d\n",com[i].bname,com[i].sales);
}
printf("\nMaximum sales of");
printf("\nBranch name=%s",max.bname);
printf("\nTotal sales=%d",max.sales);
getch();
}

***********output***********
Enter the number of branches:3
Enter branch name:
MYSORE
Enter total sales:
5266
Enter branch name:
BANGALORE
Enter total sales:
5690
Enter branch name:
MANGALORE
Enter total sales:
9526
BRANCH TOTAL SALES
--------------------------------
MYSORE 5266
BANGALORE 5690
MANGALORE 9526

Maximum sales of
Branch name=MANGALORE
Total sales=9526

Mr K Praveen Kumar, SMC, SHIRVA P a g e 28 | 28

You might also like