Skip to content

Commit 549a1fe

Browse files
authored
Create 8.c
1 parent de5bf48 commit 549a1fe

File tree

1 file changed

+51
-0
lines changed
  • Special Programs

1 file changed

+51
-0
lines changed

Special Programs/8.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include<stdio.h>
2+
int length(char *s)
3+
{
4+
int i=0;
5+
while(*(s+i)!='\0')
6+
{
7+
i++;
8+
}
9+
return i;
10+
}
11+
int compare(char *s,char *s1,int len)
12+
{
13+
int i,ascii=0,ascii_=0;
14+
for(i=0;i<len;i++)
15+
{
16+
if(*(s+i)!=*(s1+i))
17+
{
18+
ascii=ascii+(int)*(s+i);
19+
ascii_=ascii_+(int)*(s1+i);
20+
}
21+
}
22+
ascii=ascii-ascii_;
23+
return ascii;
24+
}
25+
void main()
26+
{
27+
char s[100],s1[100];
28+
int len,len1,comp;
29+
puts("Enter the 1st string ");
30+
gets(s);
31+
puts("Enter the 2nd string ");
32+
gets(s1);
33+
len=length(s);
34+
len1=length(s1);
35+
if(len==len1)
36+
{
37+
comp=compare(s,s1,len);
38+
if(comp==0)
39+
{
40+
puts("Two strings are equal.");
41+
}
42+
else
43+
{
44+
puts("Two strings are not equal.");
45+
}
46+
}
47+
else
48+
{
49+
puts("Two strings are not equal.");
50+
}
51+
}

0 commit comments

Comments
 (0)