String final questions 28

String Final Questions 28/11/22


koi bug ya error mile toh batana : >💣

android compiler apk >>compiler click here __


Q1. WAP  of string and perform these ops >>
1>cpy 
2>cmp 
3>con
4>leng by using functions of str..?   

#include<stdio.h>
#include<string.h>
int main(){
int m1,m2,m3,c,m4,m5,len1,len2,s;
char name1[15];
char name2[15];
char *result[35];
printf("write name 1\n");
gets(name1);
printf("write name 2\n");
gets(name2);
printf("\n what you want to do\n1>> copy \n2>> compare\n3>> length\n4>>concatenate\n");
scanf("%d",&c);
if (c==1){
printf("we are coping name 1 in name 2\n");
      strcpy(name2, name1);
       puts(name2);
}
else if (c==2){
s=strcmp(name1,name2);
    printf("Comparison result =%d",s);
}
else if (c==3){
len1=strlen(name1);
    printf("Length of first = %d", len1);
len2=strlen(name2);
    printf("Length of second = %d", len2);
}    
else if (c==4)
{
 result[35]=strcat(name1, name2);
    printf("String = %s", result[35]);}

return 0;
} 


Q2. WAP  of string and perform these ops >> 1>cpy ,2>cmp ,3>con ,4>leng without using function str?   

(isme kuch faltu variable le liye woh hata sakte ho)

#include <stdio.h>
int main()
{
    int m1, m2, m3, c, o=0, tem, i, m=0, m4, m5, n, len1, len2, count = 0, count2 = 0, s;
    char name1[15];
    char k;
    char name2[15];
    char *result[35];
    printf("write name 1\n");
    gets(name1);
    printf("write name 2\n");
    gets(name2);
    printf("\n what you want to do\n1>> copy \n2>> compare\n3>> length\n4>> concatenate\n");
    scanf("%d", &c);
    if (c == 1)
    {
        printf("we are coping name 1 in name 2\n");
        name2[15] = name1[15];
        puts(name2);
    }
    else if (c == 2)
    {
        for (i = 0; name1[i] != '\0'; i++)
        {
            name1[i] = k;
            k = n;
            m = n + m;
        }
        for (i = 0; name2[i] != '\0'; i++)
        {
            name2[i] = k;
            k = n;
            o = n + o;
        }
         if (m = o)
        {
            printf("result 0 >> congrats dono same likh di\n     kya kar raha hai bhai ");
        }
        else if (m > o)
        {
            printf("Comparison result +ve ");
        }

        else
        {

            printf("Comparison result -ve ");
        }
    }
    else if (c == 3)
    {
        for (i = 0; name1[i] != '\0'; i++)
        {
            count++;
        }
        printf("Length of first = %d\n", count);
        for (i = 0; name2[i] != '\0'; i++)
        {
            count2++;
        }
        printf("Length of second = %d", count2);
    }
    else if (c == 4)
    {
        printf("%s", name1);
        printf("%s", name2);
    }

    return 0;
}




Q3. WAP to count words in string ?

#include <stdio.h>
#include <string.h>
int main()
{
    char name[30];
    int i, word = 1, k = 0;
    printf("write your string ");
    gets(name);
    for (i = 0; name[i] != '\0'; i++)
    {
        if (name[i] == ' ')
        {
            word++;
            i++;
        }
        else
        {
            k++;
        }
    }
    puts(name);
    printf(" has %d words\n", word);
    return 0;
}


Q4. WAP to print ascii value of char ?


 #include<stdio.h>
 #include<string.h>
int main (){
char n='a';
printf("%c has %d value ",n,n);
return 0;
}

Comments

  1. update kar diya phele without libraray fun mein compare mein error tha

    ReplyDelete
    Replies
    1. new ::


      #include
      #include
      void count(char *a);
      int main(){
      int i, count,count1,a,b;
      char p={"abccef"};
      char *ptr;
      //char q={"def"};
      ptr=p;
      count(&p);
      return 0;
      }
      void count (char *a)
      {
      int i;
      for (i = 0; a[i] != '\0'; i++)
      {
      count++;
      }
      printf("Length of first = %d\n", count);
      }

      Delete

Post a Comment

Popular posts from this blog

O.S. MIDSEM by god

O.S. UNIT 5 (QUES/ANS)

MINI project format >> 1st sem