Showing posts with label PROGRAMS. Show all posts
Showing posts with label PROGRAMS. Show all posts

PROGRAM-27

#vpsinghrajput


// Program of reverse of string
#include
#include
#include
void main ()
{
int len,i,j;
char a[10],b;
clrscr();
printf("enter the string ");
scanf("%s",a);
len=strlen(a)-1;
for(i=len; i>=0; i--)
{
printf("%c",a[i]);
}
getch();
}





Algorithm

·                     start
·                     Declare len, i, j as integer
·                     Declare a[10] as character
·                     Write("the string ")
·                     Read(“the string”)
·                     len=strlen(a)-1
·                     for(i=len; i>=0; i--)
·                     Write(“a[i]”)
·                     Stop

PROGRAM-25

#vpsinghrajput

// Program of bubble sorting
#include
#include
void main()
{
  clrscr();
  int i,a[30],n,j,temp;
  printf("Enter the number of array: ");
  scanf("%d", &n);
  for(i=1;i<=n;i++)
 {
  printf("Enter the element of array = ");
  scanf("%d", &a[i]);
 }
 for(i=1;i<=n;i++)
 {
  for(j=1;j<=n-1;j++)
 {
  if(a[j]>a[j+1])
 {
  temp=a[j];
  a[j]=a[j+1];
  a[j+1]=temp;
 }
 }
 }
 for(i=1;i<=n;i++)
{
 printf("a[%d] = %d,",i,a[i]);
}
 getch();
}
 
Algorithm
·                     Start
·                     Declare i, a[30], n, j, temp as integer
·                     Write("the number of array")
·                     Read(“the number of array”)
·                     for(i=1;i<=n;i++)
·                     Write("the element of array")
·                     Read(“the element of array”)
·                      for(i=1;i<=n;i++)
·                     for(j=1;j<=n-1;j++)
·                     if(a[j]>a[j+1])
·                     temp=a[j]
·                     a[j]=a[j+1]
·                     a[j+1]=temp
·                     for(i=1;i<=n;i++)
·                     Read(“I and a[i]”)
·                     Stop

PROGRAM-24

#vpsinghrajput

//Program of maximum digit in array
#include
#include
void main()
{
  clrscr();
  int i,a[30],n,max;
  printf("Enter the number of array: ");
  scanf("%d", &n);
  for(i=0;i
  {
    printf("Enter the array = ");
    scanf("%d", &a[i]);
  }
   for(i=0;i
  {
   printf("a[%d] = %d,", i,a[i]);
   }
  max=a[0];
  for(i=1;i<=n-1;i++)
 {
   if(a[i]>max)
  {
   max=a[i];
  }
 }
  printf("\nmax = %d\n", max);
  getch();
}


Algorithm

·                     Start
·                     Declare i, a[30], n, max as integer
·                     Write("the number of array")
·                     Read(“the number of array”)
·                     for(i=0;i
·                     Write("the array ")
·                     Read(“a[i]”)
·                     for(i=0;i
·                     Read(“ i, a[i]”)
·                     max=a[0]
·                     for(i=1;i<=n-1;i++)
·                     if(a[i]>max)
·                     max=a[i]
·                     Read(“the maximum array”)
·                     Stop

PROGRAM-23

#vpsinghrajput

// Program of Palindrome
#include
#include
#include
void main()
{
clrscr();
char string[25], revstring[25] = {'\0'};
int i,length=0;int flag=0;
printf("Enter the string\n");
gets(string);
for(i=0;string[i]!='\0';i++)
{
length++;
}
for(i=length-1;i>=0;i--)
{
revstring[length-1] = string[i];
}
{
if(revstring[i]==string[i])
flag=1;
else
flag=0;
}
if(flag==1)
{
printf("%s is not a palindrome\n", string);
}
else
{
printf("%s is a palindrome\n", string);
}
getch();
}

Algorithm

·                     Start
·                     Declare string[25], revstring[25] = {'\0'} as character
·                     Declare i, length=0; flag=0 as integer
·                     Write("the string")
·                     gets(string)
·                     for(i=0;string[i]!='\0';i++)
·                     length++
·                     for(i=length-1;i>=0;i--)
·                     revstring[length-1] = string[i]
·                     if(revstring[i]==string[i])
·                     flag=1
·                     else
·                     flag=0
·                     if(flag==1)
·                     Read(“It is not a palindrome”)
·                     else
·                     Read("It is a palindrome")
·                     Stop

PROGRAM-22

#vpsinghrajput

// Program of struct
#include
#include
void main()
{
clrscr();
char author[20];
  struct MATH_BOOK
  {
    int book_num;
    char auther[20];
    char publish[20];
    float price;
  };
struct MATH_BOOK bkinfo;
printf("Enter the book number\n");
scanf("%d", &bkinfo.book_num);
printf("Enter the name of author\n");
scanf("%s", &author);
printf("Enter the name of publisher\n");
scanf("%s", &bkinfo.publish);
printf("Enter the price of book\n");
scanf("%f", &bkinfo.price);
printf("..............\n");
printf("         MATH_BOOK\n");
printf("..............\n");
printf("Book number  : %d       \n", bkinfo.book_num);
printf("Author       : %s       \n", author);
printf("Publisher    : %s       \n", bkinfo.publish);
printf("price        : rs.%6.2f\n", bkinfo.price);
printf("............. \n");
getch();
}













Algorithm

·                     Start
·                     Declare author[20] as character
·                     struct MATH_BOOK
·                     Declare book_num as integer
·                      Declare publish[20] as character
·                     Decxlare price as float
·                     struct MATH_BOOK bkinfo
·                     Write("the book number")
·                     Read(“book number”)
·                     Write("the name of author")
·                     Read(“the name of author”)
·                     Write("the name of publisher")
·                     Read(“the name of publisher”)
·                     Write(“the price of book”)
·                     Read(“the price of book”)
·                     Write("..............")
·                     Write("         MATH_BOOK")
·                     Write("..............")
·                     Read(“Book number”)
·                     Read("Author")
·                     Read("Publisher ")
·                     Read("price")
·                     Read("............. ")
·                     Stop



PROGRAM-21

#vpsinghrajput

//Program of concatenation
#include
#include
void main()
{
clrscr();
char string1[10],string2[10];
printf("Enter the first string\n");
scanf("%s", string1);
printf("Enter the second string\n");
scanf("%s", string2);
printf("concatenated string is   \n");
printf("%s %s", string1,string2);
getch();
}

 
Algorithm

·                     Start
·                     Declare string1[10], string2[10] as character
·                     Write("the first string")
·                     Read(“string1”)
·                     Write(“the second string”)
·                     Read("string2”)
·                     Read("concatenated string is")
·                     Read(“string1,string2”)
·                     Stop


PROGRAM-20

#vpsinghrajput

// Program of pointer
#include
#include
void main()
{clrscr();
int *ptr1,*ptr2;
static int arr[5]={11,22,33,44,55};
ptr1=&arr[1];
ptr2=&arr[4];
if(ptr1
  printf("Address %d is less than address %d\n", ptr1,ptr2);
else
  printf("Address of %d is greater or equal to address %d\n", ptr1,ptr2);
  getch();
  }







Algorithm

·                     Start
·                     Declare *ptr1,*ptr2 as integer
·                     static int arr[5]={11,22,33,44,55}
·                     ptr1=&arr[1]
·                     ptr2=&arr[4]
·                     if(ptr1
·                     Read("Address of ptr1 is less than address of ptr2)
·                     else
·                     Read("Address of ptr1 is greater or equal to address of ptr2”)
·                     Stop



PROGRAM-19

#vpsinghrajput

// Program to product of two matrices
#include
#include
void main()
{
  clrscr();
  int matA[10][10], matB[10][10], prodmat[10][10];
  int n,i,j,k,row1,col1,row2,col2;
  printf("Enter the order of matrixA\n");
  scanf("%d*%d", &row1,&col1);
  printf("Enter the order of matrixB\n");
  scanf("%d*%d", &row2,&col2);
  if(col1==row2)
     {
                printf("Enter the element of matrixA\n");
                for(i=0;i
                {
                   for(j=0;j
                     {
                     scanf("%d", &matA[i][j]);
                   }
     }
  printf("Enter the element of matrixB\n");
                for(i=0;i
     {
                for(j=0;j
                {
                  scanf("%d", &matB[i][j]);
                }
     }
                for(i=0;i
                {
                  for(j=0;j
                  {
                   prodmat[i][j]=0;
                   for(k=0;k
                   {
                   prodmat[i][j]=prodmat[i][j]+(matA[i][k]*matB[k][j]);
                   }
                  }
                 }
                 printf("Product matrix is \n");
                for(i=0;i
                {
                  for(j=0;j
                  {
                    printf("%3d", prodmat[i][j]);
                  }
                  printf("\n");
                  }
       }
       else
       printf("multiplication is not possible  \n");
       getch();
}

Algorithm

·                     Start
·                     Declare matA[10][10],  matB[10][10],  prodmat[10][10] as integer
·                       Declare n, i, j, k, row1, col1, row2, col2 as integer
·                       Write("the order of matrixA")
·                       Read(“row1 and col1”)
·                       Write("the order of matrixB")
·                       Read(“row2 and col2”)
·                       if(col1==row2)
·                     Read("Enter the element of matrixa")
·                     for(i=0;i
·                     for(j=0;j
·                     Read(“matA[i][j]”)
·                     printf("the element of matrixB")
·                     for(i=0;i
·                     for(j=0;j
·                     Read(“matB[i][j]”)
·                     for(i=0;i
·                     for(j=0;j
·                     prodmat[i][j]=0
·                     for(k=0;k
·                     prodmat[i][j]=prodmat[i][j]+(matA[i][k]*matB[k][j])
·                     Read("the Product matrix ")
·                     for(i=0;i
·                     for(j=0;j
·                     Read("the prodmat[i][j])
·                     write("in next line")
·                     else
·                     Write("multiplication is not possible")
·                     Stop