Tutorials, Free Online Tutorials,It Challengers provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, core java, sql, php, c language etc. for beginners and professionals.

Breaking

Showing posts with label C Programms. Show all posts
Showing posts with label C Programms. Show all posts
11:35 am

C Program to Concatenate Two Strings


Concatenate Two Strings Without Using strcat()


#include <stdio.h>
int main()
{
    char str1[100], s2tr[100], i, j;

    printf("Enter first string: ");
    scanf("%s", str1);

    printf("Enter second string: ");
    scanf("%s", str2);

    // calculate the length of string s1
    // and store it in i
    for(i = 0; str1[i] != '\0'; ++i);

    for(j = 0; str2[j] != '\0'; ++j, ++i)
    {
        str1[i] = str2[j];
    }

    str1[i] = '\0';
    printf("After concatenation: %s", str1);

    return 0;
}

Output:-





11:28 am

C Program to Copy String Without Using strcpy()


  Copy String Without Using strcpy()


#include <stdio.h>
int main()
{
    char str1[100], str2[100], i;

    printf("Enter string str1: ");
    scanf("%s",str1);

    for(i = 0; str1[i] != '\0'; ++i)
    {
        str2[i] = str1[i];
    }

    str2[i] = '\0';
    printf("String str2: %s", str2);

    return 0;
}




Output:-


11:07 am

C Program to Find the Frequency of Characters in a String


Find the Frequency of Characters


#include <stdio.h>
int main()
{
   char str[1000], ch;
   int i, frequency = 0;

   printf("Enter a string: ");
   gets(str);

   printf("Enter a character to find the frequency: ");
   scanf("%c",&ch);

   for(i = 0; str[i] != '\0'; ++i)
   {
       if(ch == str[i])
           ++frequency;
   }

   printf("Frequency of %c = %d", ch, frequency);
   return 0;
}

Output:-


8:54 am

WAP to convert the string from lower case to upper case


C Program to convert the string from lower case to upper case.


#include <stdio.h>
#define MAX_SIZE 100 //Maximum size of the string
int main()
{
    char string[MAX_SIZE];
    int i;
    printf("Enter your text : ");
    gets(string);
    for(i=0; string[i]!='\0'; i++)
    {
        if(string[i]>='a' && string[i]<='z')
        {
            string[i] = string[i]-32;
        }
    }

    printf("Uppercase string : %s\n",string);
    return 0;
}

8:48 am

WAP to convert the string from upper case to lower case.


C Program to convert the string from upper case to lower case.


#include<stdio.h>
#include<string.h>
int main()
{
  char string[50];
  int j;
  printf("Enter any string->");
  scanf("%s",string);
  printf("The string is->%s",string);
  for(j=0;j<=strlen(string);j++)
{
      if(string[j]>=65&&string[j]<=90)
       string[j]=string[j]+32;
  }
  printf("\nThe string in lower case is->%s",string);
  return 0;
}