-->

program to get area of circle using function named circle()

// program to get area of circle using function named circle()
#include<stdio.h>                      //header file
void circle();                              // function prototype/declaration with return type zero.
int main()                                  //main function
{
circle();                                     // function calling. you can call it as many as you want.
return 0;
}
void circle()                              // function body line ; also called function definition
{
 float radius;                            // variable declaration
float area;                                //variable declaration
printf("enter radius of circle\n");   // displays message to input data
scanf("%f",&radius);                   // gets data from user.
area=3.14*radius*radius;             // calculates result stores in area.
printf("the area is=%f\n",area);    // displays output
}
/* here we have used top down approach. i.e calling from top and writing its body line down.
 we can also reverse the process.*/

-----------------------------------------------------------------------------------------------------------------------
or
--------------------------------------------------------------------------------------------------

// program to get area of circle using function named circle(). we use here bottom up technique
#include<stdio.h>                      //header file
                                              // function prototype/declaration is not needed
void circle()                              // function body line/definition
{
 float radius;                            // variable declaration
float area;                                //variable declaration
printf("enter radius of circle\n");   // displays message to input data
scanf("%f",&radius);                   // gets data from user.
area=3.14*radius*radius;             // calculates result stores in area.
printf("the area is=%f\n",area);    // displays output
}
int main()                                  //main function
{
circle();                                     // function calling. you can call it as many as you want.
return 0;
}
// this (above method is now obsolete. if you want that you can use that. mostly we use top down.


wap to initialize strings and display them

using codeblock
-----------------------------------------------------------------------------------
// initialization of strings
#include <stdio.h>                                   // header file

int main()                                               // main function
{
    char strings[5][5]={"RAM","sita","Hary","Niraj"};// initialization of 4 strings with 2 dimensional array
    int i;                                                               // variable declaration
    for(i=0;i<=3;i++)                                          // loop which executes 4 times because we have taken 4 strings so.
    {
        printf("%s\n",strings[i]);                              //display of strings
    }
    return 0;                                                      // return statement
}

-----------------------------------------------
using turboc++
-------------------------------------
// initialization of strings
#include <stdio.h>                                   // header file
#include<conio.h>
void main()                                               // main function
{
    char strings[5][5]={"RAM","sita","Hary","Niraj"};
// initialization of 4 strings with 2 dimensional array
    int i;                                                               // variable declaration
    for(i=0;i<=3;i++)                     // loop which executes 4 times because we have taken 4 strings so.
    {
        printf("%s\n",strings[i]);                              //display of strings
    }
    getch();                                                      // to hold the output.
}

array with string programs

1) wap to initialize strings and display them.

                                                                                                               solution
2) WAP to initialize some characters and display them.
                                                                                                              solution

3)WAP  to input any five names with address and display them.

                                                                                                            solution



programs strings with library functions (in-built functions)


1) WAP to get /find length of string using(strlen()) function.

                                                                                                           solution
2)WAP to reverse a string using strrev() function.

                                                                                                         solution

3)WAP to convert string into uppercase using strupr() function.

                                                                                                            solution

4)WAP to convert string into lowercase using strlwr() function

                                                                                                            solution

5)WAP to copy a string using strcpy().

                                                                                                            solution
6) WAP to concatenate /merge two strings using strcat() function.

                                                                                                             solution
7)WAP to compare two strings using strcmp() function.

                                                                                                            solution

8) wap to look for a specific character in given string using strchr() function.


                                                                                                         solution

9)WAP to set all characters in the given string to the character using strset() function.

                                                                                                         solution
10)WAP to find initial segment of string that consists entirely of characters from second string. using strspn() function.
                                                                                                       solution

11)WAP to scan first string for the first occurrence of the substring  in string second using strstr() function.
                                                                                                     solution           

12)WAP to search a string in given list of strings.

                                                                                                     solution

without using library functions:

1) WAP to find length of string without strlen() function.

                                                                                                    solution
2)WAp to reverse a string without using strrev function().

                                                                                                     solution
3) WAP to convert given string into uppercase without using strupr() function.

                                                                                                  solution

4) WAP to convert given string into lowercase without using strlwr() function.

                                                                                                 solution

5)WAP to copy a string without using strcpy().

                                                                                                            solution
6) WAP to concatenate /merge two strings without using strcat() function.

                                                                                                             solution



combined programs:

1) Write a program to sort 'n' strings. (ascending order or descending order).


                                                                                                                          solution
2) WAP to search a  string from a set of strings.

                                                                                                                             solution
3) WAP to know a string is Palindrome or not.

                                                                                                                         solution

4) WAP swap two strings.
                                                                                                                          solution

5) WAP to count total number of vowels in a string.

                                                                                                                          solution
6)WAP to count total number of consonants in a sting.

                                                                                                                          solution
7)WAP to count total words in a string.

                                                                                                                          solution
8) WAP to count particular character in a string.

                                                                                                                         solution

9) WAP to count total spaces in a string.

                                                                                                                          solution

10)WAP to count total digits present in a string.

                                                                                                                        solution
11)WAP to replace all white spaces with a character.

                                                                                                                       solution

12)WAP to count all characters after first white space.

                                                                                                                       solution
13)WAP to print all characters before the first space.

                                                                                                                        solution


WAP to print lower triangular matrix of order mxn.

using codeblock
---------------------------
//WAP to print lower triangular matrix  of order mxn.// comment about our program
#include<stdio.h>                                    // header file where are libraries are stored
int main()                                          // main function
{
int matrics_1[100][100];                     // declaration of matrix of maximum size 100
int i,j      ;                                        // variables declaration
int total_row,total_col;                     // variables for rows and columns
printf("the matrix must be square for upper triangular\n");
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // input for total number of rows of matrix
printf("enter total columns(n)\n");
scanf("%d",&total_col);                     // input for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("matrix is\n");                  // matrix message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)
       {
           printf("%d",matrics_1[i][j]); // display of matrix with elements
        }
        printf("\n");                    // display in next row
}
printf("lower triangular matrix is\n");  // message for lower triangular matrix
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                // nested loop
       {
           if(i>=j)                       // testing the condition
           {
            printf("%d",matrics_1[i][j]);// display of lower triangular matrix with elements
           }
           else
           {
               printf("0");               // display of zero elements below diagonal if the condition did not satisfy.
           }
       }
       printf("\n");
}
 return 0;
}
----------------------------
using turboC++
--------------------------
//WAP to print lower triangular matrix  of order mxn.// comment about our program
#include<stdio.h>                                    // header file where are libraries are stored
#include<conio.h>
void main()                                          // main function
{
int matrics_1[100][100];                     // declaration of matrix of maximum size 100
int i,j      ;                                        // variables declaration
int total_row,total_col;                     // variables for rows and columns
printf("the matrix must be square for upper triangular\n");
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // input for total number of rows of matrix
printf("enter total columns(n)\n");
scanf("%d",&total_col);                     // input for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("matrix is\n");                  // matrix message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)
       {
           printf("%d",matrics_1[i][j]); // display of matrix with elements
        }
        printf("\n");                    // display in next row
}
printf("lower triangular matrix is\n");  // message for lower triangular matrix
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                // nested loop
       {
           if(i>=j)                       // testing the condition
           {
            printf("%d",matrics_1[i][j]);// display of lower triangular matrix with elements
           }
           else
           {
               printf("0");               // display of zero elements below diagonal if the condition did not satisfy.
           }
       }
       printf("\n");
}
 getch();
}

WAP to print upper triangular matrix of order mxn.

using codeblocks
-----------------------------------
//WAP to print upper triangular matrix  of order mxn.
#include<stdio.h>
int main()
{
int matrics_1[100][100];                     // declaration of matrix of maximum size 100
int i,j      ;                               // variables declaration
int total_row,total_col;                     // variables for rows and columns
printf("the matrix must be square for upper triangular\n");
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // input for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // input for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("matrix is\n");                  // matrix message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)             
       {
           printf("%d",matrics_1[i][j]); // display of matrix with elements
        }
        printf("\n");                    // display in next row
}
printf("upper triangular matrix is\n");  // message for upper triangular matrix
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                // nested loop
       {
           if(i<=j)                       // testing the condition
           {
            printf("%d",matrics_1[i][j]);// display of upper triangular matrix with elements
           }
           else
           {
               printf("0");               // display of zero elements below diagonal if the condition did not satisfy.
           }
       }
       printf("\n");
}
 return 0;       
}
-------------------------------------------------------------------
using turboC++
--------------------------------------------------------------
//WAP to print upper triangular matrix  of order mxn.
#include<stdio.h>
#include<conio.h>
void main()
{
int matrics_1[100][100];                     // declaration of matrix of maximum size 100
int i,j      ;                               // variables declaration
int total_row,total_col;                     // variables for rows and columns
printf("the matrix must be square for upper triangular\n");
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // input for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // input for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("matrix is\n");                  // matrix message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)             
       {
           printf("%d",matrics_1[i][j]); // display of matrix with elements
        }
        printf("\n");                    // display in next row
}
printf("upper triangular matrix is\n");  // message for upper triangular matrix
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                // nested loop
       {
           if(i<=j)                       // testing the condition
           {
            printf("%d",matrics_1[i][j]);// display of upper triangular matrix with elements
           }
           else
           {
               printf("0");               // display of zero elements below diagonal if the condition did not satisfy.
           }
       }
       printf("\n");
}
 getch();       
}


//WAP to get sum of diagonal elements of an array of order 'mxn'.

//WAP to get sum of diagonal elements of an array of order 'mxn'.
#include<stdio.h>
#include<conio.h>
void main()
{
int matrics_1[100][100];
int i,j,sum=0;
int total_row,total_col;
printf("for sum, the matrix must be square\n");
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("the matrix is\n");             // message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)             
       {
           printf("%d",matrics_1[i][j]); // display of matrix
        }
        printf("\n");                    // display in next row
}
printf("------------------\n");             // for transposed matrix
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)
       {
           if(i==j)                          // testing whether the locations are same or not
           {
           sum=sum+matrics_1[i][j];
            }                                // display of matrix with trasnposed elemnts
       }
       printf("\n");
}

printf("sum=%d",sum);
     
getch();
}

------------------------------------------------------------------------------------------
using codeblocks.
-------------------------------------------------------------------------------------
//WAP to get sum of diagonal elements of an array of order 'mxn'.
#include<stdio.h>
int main()
{
int matrics_1[100][100];
int i,j,sum=0;
int total_row,total_col;
printf("for sum, the matrix must be square\n");
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("the matrix is\n");             // message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)             
       {
           printf("%d",matrics_1[i][j]); // display of matrix
        }
        printf("\n");                    // display in next row
}
printf("------------------\n");             // for transposed matrix
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)
       {
           if(i==j)                          // testing whether the locations are same or not
           {
           sum=sum+matrics_1[i][j];
            }                                // display of matrix with trasnposed elemnts
       }
       printf("\n");
}

printf("sum=%d",sum);
 return 0;       
}

WAP to transpose a matrix/array of order mxn.

//WAP to transpose  a matrix/array of order mxn.
#include<stdio.h>
#include<conio.h>
void main()
{
int matrics_1[100][100];
int i,j,sum=0;
int total_row,total_col;
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("before transpose\n");             // message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)             
       {
           printf("%d",matrics_1[i][j]); // display of matrix
        }
        printf("\n");                    // display in next row
}
printf("after transpose\n");             // for transposed matrix
for(i=0;i<total_col;i++)
{
  for(j=0;j<total_row;j++)
       {
        printf("%d",matrics_1[j][i]);    // display of matrix with trasnposed elemnts
       }
       printf("\n");
}     
getch();
}
------------------------------------------------------------------------------------------
using codeblocks/devc++  with return concept
---------------------------------------------------------------------------------------
//WAP to transpose  a matrix/array of order mxn.
#include<stdio.h>
int main()
{
int matrics_1[100][100];
int i,j,sum=0;
int total_row,total_col;
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("before transpose\n");             // message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)             
       {
           printf("%d",matrics_1[i][j]); // display of matrix
        }
        printf("\n");                    // display in next row
}
printf("after transpose\n");             // for transposed matrix
for(i=0;i<total_col;i++)
{
  for(j=0;j<total_row;j++)
       {
        printf("%d",matrics_1[j][i]);    // display of matrix with trasnposed elemnts
       }
       printf("\n");
}


 return 0;       
}

-------------
change the rows to column and vice versa.