wap that reads string from the keyboard and determine whether string is a palindrome or not.




#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
char string[50],reverse[50];
int i;
printf("enter the string\t");
gets(string);
strcpy(reverse,string);
strrev(reverse);
i=stricmp(reverse,string);
if(i==0)
printf("the string entered is a palindrome");
else
printf("the enterted string is not a palindrome.");
getch();
}

wap to implement binary search.


#include<stdio.h>
int binarysearch(int list[],int low,int high,int key);
void main()
{
int list[20],num,i,key,low,high,index;
printf("enter the number of elements(max 20)\t");
scanf("%d",&num);
printf("enter the elements in ascending order");
for(i=0;i<num;i++)
scanf("%d",&list[i]);
printf("enter the key that u want to search");
scanf("%d",&key);
index=binarysearch(list,0,num-1,key);
if (index==-1)
printf("does not exist in the list");
else
printf("exists at the location %d",index+1);
}
int binarysearch(int list[],int low,int high,int key)
{
int mid;
if(low==high)
{
if(list[low]==key)
return low;
else
return -1;
}
else
{
mid=(low+high)/2;
if(list[mid]==key)
return mid;
else if(list[mid]>key)
return binarysearch(list,low,mid-1,key);
else
return binarysearch(list,mid+1,high,key);
}
}

NOTE-  i have compiled this program in codeblocks if u do it in turbo c++  use  conio.h  header file in the beginning  and getch()  a the  last


wap to initialize an array dynamically and print the elements of the array in reverse order. the size of the array and elements of the array are to be taken by the user.




#include<stdio.h>
#include<malloc.h>
void main()
{
int *array,size,i;
printf("enter the size of the array");
scanf("%d",&size);
array=(int*)malloc(size*sizeof(int));
printf("enter the elements");
for(i=0;i<size;i++)
scanf("%d",&array[i]);
for(i=size-1 ;i>=0;i--)
printf("%d",array[i]);
}

NOTE-  i have compiled this program in codeblocks if u do it in turbo c++  use  conio.h  header file in the beginning  and getch()  a the  last

wap to determine whether a given program is odd or even and print them without using else.


#include<stdio.h>
void main()
{
int a;
scanf("%d",&a);
if((a%2)==0)
printf("is an even no");
if((a%2)!=0)
printf("it is an odd number");
}


NOTE-  i have compiled this program in codeblocks if u do it in turbo c++  use  conio.h  header file in the beginning  and getch()  a the  last

wap to print the following pattern.

A
A B
A B C
A B C D
A B C D E



#include<stdio.h>
void main()
{
int i,j;
for(i=65;i<=70;i++)
{
  {
   for(j=65;j<=i;j++)
   printf("%c ",j);
   }
 printf("\n");
}
}



NOTE-  i have compiled this program in codeblocks if u do it in turbo c++  use  conio.h  header file in the beginning  and getch()  a the  last

WAP to find the GCD(greatest common divisor) of three numbers entered by the user.

#include<stdio.h>
void main()
{
int a,b,c,d,e,f,i;
scanf("%d%d%d",&a,&b,&c);
for(i=a;i>=1;i--)
{
  d=a%i;
  e=b%i;
  f=c%i;
 if((d==0)&&(e==0)&&(f==0))
 {
 printf("the GCD(greatest common divisor) of the numbers is=%d",i);
  break;
 }

 }
}



NOTE-  i have compiled this program in codeblocks if u do it in turbo c++  use  conio.h  header file in the beginning  and getch()  a the  last.

WAP TO PRINT THE FOLLOWING SERIES UPTO n NO OF COLUMNS.

*
# #
* * *
# # # #
* *  * * *
# # # # # #




#include<stdio.h>
void main()
{
int i,j,n;
printf("enter the value of n");
scanf("%d",&n);
for(i=1;i<=n;i++)
 {
   {
    if((i&1)==0)
      {
       for(j=1;j<=i;j++)
       printf("# ");
       }
     else
      {
       for(j=1;j<=i;j++)
       printf("* ");
       }
     }
  printf("\n");
  }
}




NOTE-  i have compiled this program in codeblocks if u do it in turbo c++  use  conio.h  header file in the beginning  and getch()  a the  last.

WAP to enter two square matrix of order n*n and display sum of the two matrices , sum of principal diagonal elements of the matrix formed after add, the upper triangular half of the matrix formed after addition.

#include<stdio.h>
void main()
{
int array1[10][10],array2[10][10],array3[10][10],array4[10][10],i,j,m,n,b=0;
printf("enter the size of the array");
scanf("%d%d",&m,&n);
printf("enter the elements of array1");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&array1[i][j]);
printf("enter the elements of array2");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&array2[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
array3[i][j]=array1[i][j]+array2[i][j];
printf("the elements of matrices after adding the two matrix are\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",array3[i][j]);
printf("\n");
}

for(i=0;i<m;i++)
b=b+array3[i][i];
printf("the sum of principal diagonal of the square mattrix is=%d",b);
for(i=0;i<m;i++)
for(j=0;j<m;j++)
if(i<=j)
array4[i][j]=array3[i][j];
else
array4[i][j]=0;
printf("\nthe upper half triangular matrix is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",array4[i][j]);
printf("\n");
}
 }



NOTE-  i have compiled this program in codeblocks if u do it in turbo c++  use  conio.h  header file in the beginning  and getch()  a the  last.


write a program which tells the day on 1st january of a year entered by the user. the year entered should be after 2001.

#include<stdio.h>
void main()
{
int year,i,count=0,sub;
printf("enter the year after 2001 for which u want the day");
scanf("%d",&year);
for(i=2001;i<year;i++)
{
if(((i%4==0)&&(i%100!=0))||(i%400==0))
{
    printf("leap year%d",i);
count=count+1;
}
}
printf("\nthe value of count is=%d\n",count);
sub=year-2001;
printf("%d",sub);
sub=sub+count;
printf("\nthe value of sub is=%d\n",sub);
for(sub;sub>7;sub=sub-7);
printf("\nthe value of sub is=%d\n",sub);
switch(sub)
{
case 1:
printf("tuesday");
break;
case 2:
printf("wednesday");
break;
case 3:
printf("thursday");
break;
case 4:
printf("friday");
break;
case 5:
printf("saturday");
break;
case 6:
printf("sunday");
break;
case 7:
printf("monday");
break;
}
}

NOTE-  i have compiled this program in codeblocks if u do it in turbo c++  use  conio.h  header file in the beginning  and getch()  a the  last.

Implemet Stack in python

  class Stack : def __init__ ( self , data ): self . stack = [] if ( data ): self . stack . append ( da...