0% found this document useful (0 votes)
7 views

Tol Lab

tol lab

Uploaded by

mamane bello
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Tol Lab

tol lab

Uploaded by

mamane bello
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1: //Check if a given string has even a or not.

Make sure that string is made up of on


2: #include<stdio.h>
3: #include<conio.h>
4: #include<string.h>
5: int main()
6: {
7: int i,a,c=0,f=0;
8: char A[50];
9: printf("Enter the string\n");
10: scanf("%s",&A);
11: for(i=0;i<strlen(A);i++)
12: {
13: if(A[i]=='a')
14: {
15: c=c+1;
16: }
17: }
18: if(c%2==0)
19: {
20: printf("\nThe Given string have even number of a's ");
21: }
22: else
23: {
24: printf("\nThe Given string not have even number of a's ");
25: }
26:
27: for(i=0;i<strlen(A);i++)
28: {
29: if(A[i]=='a'|| A[i]=='b')
30: {
31: f=f;
32: }
33: else
34: {
35: f=1;
36: }
37: }
38: if(f==1)
39: {
40: printf("\nThe string also contains other than a and b.");
41: }
42: else
43: {
44: printf("\nThe string is made up of only a and b.");
45: }
46: return 0;
47: }
1: //Check if a given string has even a and odd b. String should made up of only a and
2: #include<stdio.h>
3: #include<conio.h>
4: #include<string.h>
5: int main()
6: {
7: int i,a,ac=0,bc=0,f=0;
8: char A[50];
9: printf("Enter the string\n");
10: scanf("%s",&A);
11: for(i=0;i<strlen(A);i++)
12: {
13: if(A[i]=='a')
14: {
15: ac=ac+1;
16: }
17: if(A[i]=='b')
18: {
19: bc=bc+1;
20: }
21: }
22: if(ac%2==0&&bc%2==0)
23: {
24: printf("\nThe Given string have even number of a's and b's");
25: }
26: else if(ac%2==0&&bc%2!=0)
27: {
28: printf("\nThe Given string have even number of a's and odd number of b's");
29: }
30: else if(ac%2!=0&&bc%2!=0)
31: {
32: printf("\nThe Given string have odd number of a's and b's");
33: }
34: else
35: {
36: printf("\nThe Given string have odd number of a's and even number of b's");
37: }
38:
39: for(i=0;i<strlen(A);i++)
40: {
41: if(A[i]=='a'|| A[i]=='b')
42: {
43: f=f;
44: }
45: else
46: {
47: f=1;
48: }
49: }
50: if(f==1)
51: {
52: printf("\nThe string also contains other than a and b.");
53: }
54: else
55: {
56: printf("\nThe string is made up of only a and b.");
57: }
58: return 0;
59: }
1: //Check if a sting over 0 and 1 ends with 0.
2: #include<stdio.h>
3: #include<conio.h>
4: #include<string.h>
5: int main()
6: {
7: int i,a,f=0,n;
8: char A[50];
9: printf("Enter the string\n");
10: scanf("%s",&A);
11: n=strlen(A);
12: for(i=0;i<strlen(A);i++)
13: {
14: if(A[i]=='0'|| A[i]=='1')
15: {
16: f=f;
17: }
18: else
19: {
20: f=1;
21: }
22: }
23: if(A[n-1]=='0'&&f==0)
24: {
25: printf("\n\nThe given string is over 0 and 1 ends with 0");
26: }
27: else if(A[n-1]!='0'&&f==0)
28: {
29: printf("\n\nThe given string is over 0 and 1 not ends with 0");
30: }
31: else
32: {
33: printf("\n\nThe given string is not over 0 and 1 only it also contains other than 0 and
34: }
35: return 0;
36: }
37:
1: //Check if a given string is a valid integer.
2: #include<stdio.h>
3: #include<conio.h>
4: #include<string.h>
5: int main()
6: {
7: int i,j,a,f1=0,f2=0,n;
8: char A[50],D[20]="+-0123456789";
9: printf("Enter the string\n");
10: scanf("%s",&A);
11: for(i=0;i<strlen(D);i++)
12: {
13: if(A[0]==D[i])
14: {
15: f1=1;
16: }
17: }
18: if(f1==1)
19: {
20: for(i=1;i<strlen(A);i++)
21: {
22: f2=0;
23: for(j=2;j<strlen(D);j++)
24: {
25: if(A[i]==D[j])
26: {
27: f2=1;
28: }
29: }
30: if(f2==0)
31: {
32: printf("\nInvalid Integer String\n");
33: break;
34: }
35: }
36: if(f2==1)
37: {
38: printf("\nValid Integer String\n");
39: }
40: }
41: else
42: {
43: printf("\nInvalid Integer String\n");
44: }
45: return 0;
46: }
47:
1: //Check if a given string is a valid identifier.
2: #include<stdio.h>
3: #include<conio.h>
4: #include<string.h>
5: int main()
6: {
7: int i,j,a,f1=0,f2,n;
8: char A[50],D[70]="abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVXXYZ_",D2[60]="_
9: printf("Enter the string\n");
10: //scanf("%s",&A);
11: gets(A);
12: printf("%s",A);
13: for(i=0;i<strlen(D2);i++)
14: {
15: if(A[0]==D2[i])
16: {
17: f1=1;
18: }
19: }
20: if(f1==1)
21: {
22: for(i=1;i<strlen(A);i++)
23: {
24: f2=0;
25: for(j=0;j<strlen(D);j++)
26: {
27: if(A[i]==D[j])
28: {
29: f2=1;
30: }
31: }
32: if(f2==0)
33: {
34: printf("\nInvalid Identifier.. \n");
35: break;
36: }
37: }
38: if(f2==1)
39: {
40: printf("\nValid Identifier.. \n");
41: }
42: }
43: else
44: {
45: printf("\nInvalid Identifier..\n");
46: }
47: return 0;
48: }
49:
50:
1: //Check if a string over a and b is a palindrome.
2: #include<stdio.h>
3: #include<conio.h>
4: #include<string.h>
5: int main()
6: {
7: int i,a,f1=0,f2=0,n,m;
8: char A[50];
9: printf("Enter the string\n");
10: scanf("%s",&A);
11: for(i=0;i<strlen(A);i++)
12: {
13: if(A[i]=='a'|| A[i]=='b')
14: {
15: f1=f1;
16: }
17: else
18: {
19: f1=1;
20: }
21: }
22: m=strlen(A)/2;
23: n=strlen(A)-1;
24: for(i=0;i<m;i++)
25: {
26: if(A[i]!=A[n-i])
27: {
28: f2=1;
29: }
30: }
31: if(f1==1&&f2==0)
32: {
33: printf("\nThe string also contains other than a and b. It creates palindrome.\n");
34: }
35: else if(f1==0&&f2==1)
36: {
37: printf("\nThe string is made up of only a and b. It Not Creates palindrome.\n");
38: }
39: else if(f1==0&&f2==0)
40: {
41: printf("\nThe string is made up of only a and b. It Creates palindrome.\n");
42: }
43: else
44: {
45: printf("\nInvalid string\n");
46: }
47: return 0;
48: }

You might also like