-->

NEB26:program to reverse a number using function reverse()

//program to reverse a number using function reverse()
#include<stdio.h>
#include<conio.h>
void reverse();
void main()
{
prinf("the output is\n");
reverse();
getch();
}
void reverse()
{
int num;
int rem;
printf("enter a number\n");
scanf("%d",&num);
while(num!=0)
{
 rem=num%10;
    printf("%d",rem);
num=num/10;
}
------------------------
or simply we can also use strrev() function.



NEB24:explanation of string handling functions

Ans-
String--
           It means series of characters used in our program. We can also use digits with characters. They also act as string or a part of it. It is used when we input our name or address or somewhere their combination.

Syntax
char identifier[value];
or char identifier[value][value];

We can use he upper one if we want to input single string then. And if we want to input multiple values then we use lower one(called 2-dimensional array in string).

For example,
char name[100];
gets(name)
Here, the variable accepts value having maximum characters 100. We can also write ,
char name[10]="kathmandu";
IT stores the value in following way.

It stores values from cell location '0' and ends at null character called escape sequence. This is used to show that there is no more character beyond that. This null character is used with strings only. For  numbers, it is not used.
                        Similarly, if we want to store multiple string with same name then one-dimensional is not applicable. We use two dimensional string.
We declare:

char name[5][50];
It means, we are going to store any five names having optimum 50 characters.
Let's look below. If we have five names :RAM,SHYAM,Nita then it would like

so sequentially it stores data in different row. We use loop to execute it with different data.
Or, instead of inputting string, if we initialize strings then it can be written as
  char name[5][50]={"RAM","Shyam","Nitu"};

String handling functions:-There are some in-built functions,  we can say in-built small program. It is used to make our program easier and faster.
      Let's know about some.
1) strlen(string);-It is used to get length of given string.

 syntax:
identifer=strlen(string);
For example,
#include<stdio.h>
#include<string.h>
void main()
{
char string[100]="apple";
int k;
k=strlen(string);
printf("length=%d",k);
}
It returns 5. It also counts white spaces present in a string.
If we want want , we can also input string using scanf() or gets().

2)strrev():- It reverses the string given by us.

syntax:- strrev(string);
example:

#include<stdio.h>
#include<string.h>
void main()
{
char string[100]="apple";
printf("reverseed string=%s",strrev(string));
}

We get output "elppa". Instead of putting in output line, we can put it before printf.

3)strlwr(): This function is used to convert given string into lower case.
syntax:-
strlwr(string);
Example;
#include<stdio.h>
#include<string.h>
void main()
{
char string[100]="APPLE";
printf("string in lowercase=%s",strlwr(string));
}

It gives us "apple" as an  output.

4)strupr():This string function is used to convert all characters of  string into upper case.

syntax:
strupr(string);

example:-
#include<stdio.h>
#include<string.h>
void main()
{
char string[100]="apple";
printf("string in uppercase=%s",strupr(string));
}

We get APPLE as an output after execution.

5)strcpy();- We use this function to copy one string to another. while copying, one replaces another.
Syntax:-
strcpy(string1,string2);
or strcpy(destination,source);

When we copy string, this is done from source to destination (string2 to string1). If first is empty then there would not be over-writing.

Example;
#include<stdio.h>
#include<string.h>
void main()
{
char string1[100]="APPLE";
char string2[100]="grapes";
printf("copied string =%s",strcpy(string1,string2));
}

output-
We get here string1=grapes. Because 'grapes' is copied to firs string named "APPLE". We can also write in reverse order.

Like these all, we have many other string handling functions like, strcat(),strchr(),strdup(),strset() etc.





NEB23;program to sort 'n' number in descending order

//program to sort 'n' elements in descending order
  #include<stdio.h>
  #include<conio.h>
  void main()
  {
  clrscr();
  int arr[200];    
  int size;     
  int i,j,k;      
 printf("now,enter size of elements \n");
  scanf("%d",&size); 
printf("enter array's elements\n");                 
  for(i=0;i<size;i++)
   {                            
     printf("enter elements for location=%d\n",i);
     scanf("%d",&arr[i]);      
   }
   printf("elements' sorting process started\n");
   for(i=0;i<size;i++)
   {
       for(j=i+1;j<size;j++)
        {
           if(arr[i]<arr[j])
             {
                 k=arr[i];
                 arr[i]=arr[j];
                arr[j]=k;
             }
       }
}
printf("in descending order,elements are\n");
for(i=0;i<size;i++)
   {                            
     printf("%d\n",arr[i]);      
   }
getch();
}

NEB23;program to sort 'n' number in ascending order

//program to sort 'n' elements in ascending order
  #include<stdio.h>
  #include<conio.h>
  void main()
  {
  clrscr();
  int arr[200];    
  int size;     
  int i,j,k;      
 printf("enter size of elements \n");
  scanf("%d",&size); 
printf("enter array's elements\n");                 
  for(i=0;i<size;i++)
   {                            
     printf("enter elements for location=%d\n",i);
     scanf("%d",&arr[i]);      
   }
   printf("elements' sorting process started\n");
   for(i=0;i<size;i++)
   {
       for(j=i+1;j<size;j++)
        {
           if(arr[i]>arr[j])
             {
                 k=arr[i];
                 arr[i]=arr[j];
                arr[j]=k;
             }
       }
}
printf("in ascending order,elements are\n");
for(i=0;i<size;i++)
   {                            
     printf("%d\n",arr[i]);      
   }
getch();
}

NEB23;program to sort any 'n' names

//program to sort 'n' elements 
  #include<stdio.h>
  #include<conio.h>
  void main()
  {
  clrscr();
  int arr[200][200],temp;    
  int size;     
  int i,j;      
 printf("enter size of string \n");
  scanf("%d",&size); 
printf("enter strings\n");                 
  for(i=0;i<size;i++)
   {                            
     printf("enter string for location=%d\n",i);
     scanf("%s",&arr[i]);      
   }
   printf("elements' sorting process started\n");
   for(i=0;i<size;i++)
   {
       for(j=i+1;j<size;j++)
        {
           if((strcmp(arr[i],arr[j]))>0)
             {
                 strcpy(temp,arr[i]);
                 strcpy(arr[i],arr[j]);
                strcpy(arr[j],temp);
             }
       }
}
printf("in ascending order,elements are\n");
for(i=0;i<size;i++)
   {                            
     printf("%s\n",arr[i]);      
   }
       
 printf("in descending order....\n");

for(i=0;i<size;i++)
   {
       for(j=i+1;j<size;j++)
        {
           if((strcmp(arr[i],arr[j]))<0)
             {
                 strcpy(temp,arr[i]);
                 strcpy(arr[i],arr[j]);
                strcpy(arr[j],temp);
             }
       }
}
printf("in descending order,elements are\n");
for(i=0;i<size;i++)
   {                            
     printf("%s\n",arr[i]);      
   }   
 getch();
}

Neb22:program to get difference of two matrices of order mxn

//program to get difference of two matrices of order mxn
#include<stdio.h>
#include<conio.h>
void main()
{
int matrics_1[100][100],matrics_2[100][100];
int i,j;
int total_row,total_col;
printf("enter total number of rows(m)\n");
scanf("'%d",&total_row);
printf("'enter total columns(n)\n");;
scanf("%d",&total__col);
printf("enter elements of first matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)
       {
           scanf("%d",&matrics_1[i][j]);
        }
}
printf("now enter for second matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)
       {
           scanf("%d",&matrics_2[i][j]);
        }
}
 printf("the summed matrix is\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)
       {
           printf("%d",matrics_1[i][j]-matrics_2[i][j]);
        }
      printf(\n");
}
getch();

hseb21:;program to get sum of two matrices of order mxn

///program to get sum of two matrices of order mxn
#include<stdio.h>
#include<conio.h>
void main()
{
int matrics_1[100][100],matrics_2[100][100];
int i,j;
int total_row,total_col;
printf("enter total number of rows(m)\n");
scanf("'%d",&total_row);
printf("'enter total columns(n)\n");;
scanf("%d",&total__col);
printf("enter elements of first matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)
       {
           scanf("%d",&matrics_1[i][j]);
        }
}
printf("now enter for second matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)
       {
           scanf("%d",&matrics_2[i][j]);
        }
}
 printf("the summed matrix is\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)
       {
           printf("%d",matrics_1[i][j]+matrics_2[i][j]);
        }
      printf(\n");
}
getch();
}