EmbLogic's Blog

comparing strings which are given by the user & displaying the result on the screen…..

1 #include<stdio.h>
2 #include<string.h>
3
4 int main()
5 {
6   int n1,n2,i;
7
8         printf(“\n\nfirst enter the number of max. words u will enter in each strings  “);
9         printf(“\n\nin first string words u will use are : “);
10         scanf(“%d”,&n1);
11         printf(“\n\nin second string words u will use are : “);
12         scanf(“%d”,&n2);
13
14   char s1[n1],s2[n2];
15
16         printf(“\n\nnow enter first string :  “);
17         scanf(“%s”,&s1);
18         printf(“\n\nnow enter second string :  “);
19         scanf(“%s”,&s2);
20
21         if(n1>n2)
22         {
23                 for(i=0;i<n1;i++)
24                 {
25                         if(s1[i]>s2[i])
26                         {
27                                 printf(“\n\nthe first string is greater than second\n\n”);
28                                 goto x;
29                         }
30
31                         else if(s1[i]<s2[i])
32                         {
33                                 printf(“\n\nthe first string is less                        than second\n\n”);
34                                 goto x;
35                         }
36                 }
37         }
38
39
40
41         else if(n1<n2)
42         {
43                 for(i=0;i<n2;i++)
44                 {
45                         if(s1[i]>s2[i])
46                         {
47                                 printf(“\n\nthe first string is greater than second\n\n”);
48                                 goto x;
49                         }
50
51                         else if(s1[i]<s2[i])
52                         {
53                                 printf(“\n\nthe first string is less than second\n\n”);
54                                 goto x;
55                         }
56                 }
57         }
58
59
60
61         else if(n1==n2)
62         {
63                 for(i=0;i<n2;i++)
64                 {
65                         if(s1[i]>s2[i])
66                         {
67                                 printf(“\n\nthe first string is greater than second\n\n”);
68                                 goto x;
69                         }
70
71                         else if(s1[i]<s2[i])                                 72                         {
73                                 printf(“\n\nthe first string is less than second\n\n”);
74                                 goto x;
75                         }
76                 }
77         }
78
79
80 x:return 0;
81 }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>