Question:4
C program to input for a string, pass it to a function and display total lower case alphabets in the string.
Sol:
#include<stdio.h>
void show(char n[])
{
int i=0,la=0;
while(n[i]!='\0')
{
printf("%c\n",n[i]);
if(n[i]>='a' && n[i]<='z')
la++;
i++;
}
printf("Length of string %d\n",i);
printf("Total lower case alphabets in string %d\n",la);
}
int main()
{
char n[30];
printf("Enter any string ");
gets(n);
show(n);
}
/* Output */ Enter any string Hello HOW Are You H e l l o H O W A r e Y o u Length of string 17 Total lower case alphabets in string 8
Question:5
C program to input for a string, pass it to a function and display total upper case alphabets in the string.
Sol:
#include<stdio.h>
void show(char n[])
{
int i=0,ua=0;
while(n[i]!='\0')
{
printf("%c\n",n[i]);
if(n[i]>='A' && n[i]<='Z')
ua++;
i++;
}
printf("Length of string %d\n",i);
printf("Total Upper case alphabets in string %d\n",ua);
}
int main()
{
char n[30];
printf("Enter any string ");
gets(n);
show(n);
}
/* Output */ Enter any string Hello How Are You H e l l o H o w A r e Y o u Length of string 17 Total Upper case alphabets in string 4
Question:6
C program to input for a string, pass it to a function and display total digits in the string.
Sol:
#include<stdio.h>
void show(char n[])
{
int i=0,d=0;
while(n[i]!='\0')
{
printf("%c\n",n[i]);
if(n[i]>='0' && n[i]<='9')
d++;
i++;
}
printf("Length of string %d\n",i);
printf("Total digits in string %d\n",d);
}
int main()
{
char n[30];
printf("Enter any string ");
gets(n);
show(n);
}
/* Output */ Enter any string Hell123 How34 Are You76 H e l l 1 2 3 H o w 3 4 A r e Y o u 7 6 Length of string 23 Total digits in string 7




