-->

WAP TO GET LENGTH OF STRING USING FUNCTION

in turbcoC++
-----------------------------------------------------------------

//program to find length of a string. USe no arguments and return its value
#include <stdio.h>                           // header file to control input and output
#include<string.h>                           //header file to handle string function
#include<conio.h>                          // header file to control console input and output
int string_length();                       // function prototype
int main()                                  // main function returning integer value
{
   printf("length=%d", string_length());                       // function calling
    getch();                                 // holds input and output
    return 0;                              // returning value 0
}
int string_length()                       // function body
{
  char string[100];                       // string declaration
  int length;
  puts("enter string");                   // message printing
  gets(string);                           // gets string from user
  length=strlen(string);     // displays length with the help of strlen() function
   return length;            //returns value to length
}








-------------------------------------------------------------------------------------------
in codeblocks:
--------------------------------------------------------------------------------------------
//program to find length of a string. USe no arguments and return its value
#include <stdio.h>                           // header file to control input and output
#include<string.h>                           //header file to handle string function
#include<conio.h>                          // header file to control console input and output
int string_length();                       // function prototype
int main()                                  // main function returning integer value
{
   printf("length=%d", string_length());                       // function calling
    getch();                                 // holds input and output
    return 0;                              // returning value 0
}
int string_length()                       // function body
{
  char string[100];                       // string declaration
  int length;
  puts("enter string");                   // message printing
  gets(string);                           // gets string from user
  length=strlen(string);     // displays length with the help of strlen() function
   return length;            //returns value to length
}

1)WAP to get factorial value of a number using function.It returns value with no parameter.

in turboc++
------------------------------------------------------------------------
//program to find factorial value of a number using function with returning value.
#include<stdio.h>                      //header file
#include<conio.h>
int factorial();                          // function prototype/declaration with return type int.
int main()                              //main function
{
printf("value=%d",factorial());// function calling and printing output.
getch();
return 0;                                       //returns 0 value
}
int factorial()                             // function body line ; also called function definition
{
 int i,n,facto=1;                    // variable declaration with 1 initialization
printf("enter a number\n");    //message display to input a number
scanf("%d",&n);                //gets input
for(i=1;i<=n;i++)       //loop running from 1 to n with increment 1 each time
{
       facto=facto*i;        //  multiplication of numbers repetitively
}
  return facto;         //returning facto value
}



----------------------------------------------------------------------------------------------
in codeblocks
--------------------------------------------------------------------------------------------------
//program to find factorial value of a number using function with returning value.
#include<stdio.h>                      //header file
int factorial();                          // function prototype/declaration with return type int.
int main()                              //main function
{
printf("value=%d",factorial());// function calling and printing output.
return 0;                                       //returns 0 value
}
int factorial()                             // function body line ; also called function definition
{
 int i,n,facto=1;                    // variable declaration with 1 initialization
printf("enter a number\n");    //message display to input a number
scanf("%d",&n);                //gets input
for(i=1;i<=n;i++)       //loop running from 1 to n with increment 1 each time
{
       facto=facto*i;        //  multiplication of numbers repetitively
}
  return facto;         //returning facto value
}

WAP to convert string into lowercase.PAss string as parameter and return as an output.

in turbo c++
----------------------------------------------------------------------------

//WAP to convert a string into lowercase using(strlwr()) function.Pass string as parameter and return its result
#include <stdio.h>
#include<string.h>
#include<conio.h>
char *stringlwr(char string[]);//prototype of function(must as pointer)
int main()
{
    char name[100];// declaration
    printf("enter first string\n");
    //fgets(name, sizeof (name), stdin);//can be used
    gets(name); //string input
    printf("string in lowercase=%s\n",stringlwr(name));//prints with calling
     getch();
    return 0;
}
char *stringlwr(char string[])
{
    strlwr(string);
    return string;
}

----------------------------------------------------------------------------------------------------
in codeblocks:
------------------------------------------------------------------------------------------------
//WAP to convert a string into lowercase using(strlwr()) function.Pass string as parameter and return its result
#include <stdio.h>
#include<string.h>
#include<conio.h>
char *stringlwr(char string[]);//prototype of function(must as pointer)
int main()
{
    char name[100];// declaration
    printf("enter first string\n");
    //fgets(name, sizeof (name), stdin);//can be used
    gets(name); //string input
    printf("string in lowercase=%s\n",stringlwr(name));//prints with calling
     getch();
    return 0;
}
char *stringlwr(char string[])
{
    strlwr(string);
    return string;
}

WAP to copy a string .Pass strings as parameter. Return that as output.

in turboc++
---------------------------------------------------------------


//WAP to copy a string using(strcpy()) function.Pass string as parameter and return its result
#include <stdio.h>
#include<string.h>
#include<conio.h>
char *stringcpy(char string[],char string1[]);//prototype of function(must as pointer)
int main()
{
    char name[100],name1[100];// declaration
    printf("enter first string\n");
    //fgets(name, sizeof (name), stdin);//can be used
    gets(name); //string input
    printf("copied string=%s\n",stringcpy(name1,name));//prints with calling
     getch();
    return 0;
}
char *stringcpy(char string[],char string1[])
{
    strcpy(string,string1);
    return string;
}






---------------------------------------------------------------------------------------------------
in codeblocks:
----------------------------------------------------------------------------------------------------
//WAP to copy a string using(strcpy()) function.Pass string as parameter and return its result
#include <stdio.h>
#include<string.h>
#include<conio.h>
char *stringcpy(char string[],char string1[]);//prototype of function(must as pointer)
int main()
{
    char name[100],name1[100];// declaration
    printf("enter first string\n");
    //fgets(name, sizeof (name), stdin);//can be used
    gets(name); //string input
    printf("copied string=%s\n",stringcpy(name1,name));//prints with calling
     getch();
    return 0;
}
char *stringcpy(char string[],char string1[])
{
    strcpy(string,string1);
    return string;
}

Wap to concatenate two strings.Pass string as parameter and return the result.

in turboc++
--------------------------------------------------------------------------------
//WAP to concatenate two  strings using(strcat()) function.Pass string as parameter and return its result
#include <stdio.h>
#include<string.h>
#include<conio.h>
char *stringcat(char string[],char string1[]);//prototype of function(must as pointer)
int main()
{
    char name[100],name1[100];// declaration
    printf("enter first string\n");
    //fgets(name, sizeof (name), stdin);//can be used
    gets(name); //first string input
    printf("enter second string\n");
    gets(name1);//second string input
    printf("merged string=%s\n",stringcat(name,name1));//prints with calling
     getch();
    return 0;
}
char *stringcat(char string[],char string1[])
{
    strcat(string,string1);
    return string;
}










------------------------------------------------------------------------------------------------------
in codeblocks:
-------------------------------------------------------------
//WAP to concatenate two  strings using(strcat()) function.Pass string as parameter and return its result
#include <stdio.h>
#include<string.h>
#include<conio.h>
char *stringcat(char string[],char string1[]);//prototype of function(must as pointer)
int main()
{
    char name[100],name1[100];// declaration
    printf("enter first string\n");
    //fgets(name, sizeof (name), stdin);//can be used
    gets(name); //first string input
    printf("enter second string\n");
    gets(name1);//second string input
    printf("merged string=%s\n",stringcat(name,name1));//prints with calling
     getch();
    return 0;
}
char *stringcat(char string[],char string1[])
{
    strcat(string,string1);
    return string;
}

WAP to reverse a string.Pass string as parameter and return its reverse.

in turboc++
----------------------------------------------------------------------------------------------
//WAP to reverse a string using(strrev()) function.Pass string as parameter and return its reverse
#include <stdio.h>
#include<string.h>
#include<conio.h>
char *stringrev(char string[100]);  //function prototype with pointer type. We can avoid it size.
int main()
{
    char name[100];//two dimensional declaration
    printf("enter string\n");
    //fgets(name, sizeof (name), stdin);
    scanf("%[^\n]s",name); //it also CAN BE USED. IT accepts string with space until it meets new line

    printf("reverse=%s\n",stringrev(name));//prints the reversed name by calling the function
     getch();
    return 0;
}
char *stringrev(char string[100])
{
    strrev(string);
    return string;                              //returning its string
}

---------------------------------------------------------------------------------------
in codeblocks:
-------------------------------------------------------------------------------------
//WAP to reverse a string using(strrev()) function.Pass string as parameter and return its reverse
#include <stdio.h>
#include<string.h>
#include<conio.h>
char *stringrev(char string[100]);
int main()
{
    char name[100];//two dimensional declaration
    printf("enter string\n");
    //fgets(name, sizeof (name), stdin);
    scanf("%[^\n]s",name); //it also CAN BE USED. IT accepts string with space until it meets new line

    printf("reverse=%s\n",stringrev(name));//prints the name
     getch();
    return 0;
}
char *stringrev(char string[100])
{
    strrev(string);
    return string;
}

WAP to search a number in a list of numbers using array as a parameter.

in turboc++
-----------------------------------------------------------------------------------------
/*WAP to input elements and search a number in that.
Pass Weight as an array as parameter.*/
#include<stdio.h>
#include<conio.h>
int search_in_array(float array[200],int size,int number);//prototype with array and size and number parameters
int main()
{

float arr[200];int k,num;            // array declaration with maximum limit 200
int size,f;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
printf("enter elements\n");
for(k=0;k<size;k++)//loop execution
{
   scanf("%f",&arr[k]);//data inputs
}
printf("enter number to be searched\n");
scanf("%d",&num);                //number input to be searched
f=search_in_array(arr,size,num);//assigning return value to variable f
if(f==0)                        //testing the value
{
printf("number not found \n");//calling of function
}
else
{
    printf("number found and lcoation=%d",f);
}
getch();
return 0;
}
int search_in_array(float array[200],int size,int number)//body line
{

int k;//declaration
int found;

for(k=0;k<size;k++)//loop execution

{
 if(number==array[k])
        {
            found=0; //assigning 0 on its finding
            break;
        }
        else
        {
            found=1;//else assigning 1
        }
}
if(found==0)//testing the condition
{
    return k;//returning the location
}
    else
{
        return 0;//returning nothing
}
    getch();
}






--------------------------------------------------------------------------------------------
in codeblocks:
--------------------------------------------------------------------------------------------------------------
/*WAP to input elements and search a number in that.
Pass Weight as an array as parameter.*/
#include<stdio.h>
#include<conio.h>
int search_in_array(float array[200],int size,int number);//prototype with array and size and number parameters
int main()
{

float arr[200];int k,num;            // array declaration with maximum limit 200
int size,f;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
printf("enter elements\n");
for(k=0;k<size;k++)//loop execution
{
   scanf("%f",&arr[k]);//data inputs
}
printf("enter number to be searched\n");
scanf("%d",&num);                //number input to be searched
f=search_in_array(arr,size,num);//assigning return value to variable f
if(f==0)                        //testing the value
{
printf("number not found \n");//calling of function
}
else
{
    printf("number found and lcoation=%d",f);
}
getch();
return 0;
}
int search_in_array(float array[200],int size,int number)//body line
{

int k;//declaration
int found;

for(k=0;k<size;k++)//loop execution

{
 if(number==array[k])
        {
            found=0; //assigning 0 on its finding
            break;
        }
        else
        {
            found=1;//else assigning 1
        }
}
if(found==0)//testing the condition
{
    return k;//returning k value
}
    else
{
        return 0;//returning nothing
}
    getch();
}