Professional Documents
Culture Documents
Aparannha Roy (CSE.20.48) 24.06.2021
Aparannha Roy (CSE.20.48) 24.06.2021
Roll:- CSE/20/48
= #include <stdio.h>
#include <string.h>
int main()
{
char str[100];
int i, len, flag;
flag = 0;
len = strlen(str);
return 0;
}
Output:-
= #include<stdio.h>
#include<string.h>
int main()
{
char str[20];
int i=0,l;
printf("Enter the string:");
gets(str);
while(str[i]!='\0')
{
i++;
}
l=i;
printf("String length is %d",l);
return 0;
}
Output:-
= #include <stdio.h>
#include <string.h>
int main()
{
char s[1000];
int i,j,k,count=0,n;
for(j=0;s[j];j++);
n=j;
for(i=0;i<n;i++)
{
count=1;
if(s[i])
{
for(j=i+1;j<n;j++)
{
if(s[i]==s[j])
{
count++;
s[j]='\0';
}
}
printf(" '%c' = %d \n",s[i],count);
return 0;
}
Output:-
= #include<stdio.h>
#include<string.h>
int main()
{
char st[20];
int i,l,v=0,sp=0,c=0;
printf("Enter the string");
gets(st);
l=strlen(st);
for(i=0;i<l;i++)
{
if(st[i]=='a'||st[i]=='e'||st[i]=='i'||st[i]=='o'||st[i]=='u'||st[i]=='A'||s
t[i]=='E'||st[i]=='I'||st[i]=='O'||st[i]=='U')
{
v++;
}
else if((st[i]>='a'&&st[i]<='z')||(st[i]>='A'&&st[i]<='Z'))
c++;
else
sp++;
}
printf("vowels=%d\nconsonant= %d\n spch= %d",v,c,sp);
return 0;
}
Output:-
= #include <stdio.h>
int main()
{
char text[1000], blank[1000];
int c = 0, d = 0;
printf("Enter some text\n");
gets(text);
blank[d] = '\0';
return 0;
}
Output:-
6. Write a program to count total number of a particular word in a
given string.
= #include <stdio.h>
int stringLength(char*);
int main()
{
char str[100]={0};
int length;
while(txt[i++]!='\0'){
count+=1;
}
return count;
}
Output:-
7. Write a program to count the length of a given string without
using strlen() function also count total number of characters of
that string.
= #include <stdio.h>
#include <string.h>
int main()
{
char s[200];
int count = 0, i;
Output:-
8. Write a program to merge 2nd string at the end of 1 st string
without using strcat() function.
= #include<stdio.h>
int main(int)
{
char str1[25],str2[25];
int i=0,j=0;
printf("\nEnter First String:");
gets(str1);
printf("\nEnter Second String:");
gets(str2);
while(str1[i]!='\0')
i++;
while(str2[j]!='\0')
{
str1[i]=str2[j];
j++;
i++;
}
str1[i]='\0';
printf("\nConcatenated String is %s",str1);
return 0;
}
Output:-
9. Write a program to copy a string into another string without
using strcpy() function.
=
#include <stdio.h>
#include <string.h>
int main()
{
char Str1[100], Str2[100];
int result, i;
return 0;
}
Output :-
= #include <stdio.h>
int main() {
char s1[100], s2[100], i;
printf("Enter string s1: ");
fgets(s1, sizeof(s1), stdin);
s2[i] = '\0';
printf("String s2: %s", s2);
return 0;
}
Output:-
11. Write a program to sort a set of string in ascending order
according to alphabet with the help of Bubble sort Technique.
= #include<stdio.h>
#include<string.h>
int main(){
int i,j,count;
char str[25][25],temp[25];
puts("How many strings you are going to enter: ");
scanf("%d",&count);
return 0;
}
Output:-
= #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char ch[100];
printf("Enter your number: ");
gets(ch);
convert_to_words(ch);
return 0;
}
void convert_to_words(char *num){
int len = strlen(num);
if (len == 0){
fprintf(stderr, "empty string\n");
return;
}
if (len > 4){
fprintf(stderr,
"Length more than 4 is not supported\n");
return;
}
char *single_digits[] = {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine"};
else{
if(*num == '1'){
int sum = *num - '0' + *(num + 1) - '0';
printf("%s\n", two_digits[sum]);
return;
}
else if (*num == '2' && *(num + 1) == '0'){
printf("twenty\n");
return;
}
else{
int i = *num - '0';
printf("%s ", i ? tens_multiple[i] : "");
++num;
if (*num != '0')
printf("%s ",single_digits[*num - '0']);
}
}
++num;
}
}
Output:-