Palindrome

#vpsinghrajput
 //WAP In C String is Palindrome
#include
void main()
 {
   char *S;
   int a,b;
   clrscr();
   printf("enter the sring->\t");
   scanf("%s",S);
   for(a=0;*(S+a)!='\0';a++);
   a=a-1;
   for(b=0;*(S+b)!='\0';b++)
     {
       if(*(S+b)!=*(S+a))
     {
        printf("it is not palindrome");
        getch();
        exit(1);
     }
       a=a-1;
     }
    printf("\n\n\n\n\t\t\t\tit is palindrome");
    getch();
 }

Find out area of Triangle

#vpsinghrajput
/* formula is sqrt(s(s-a)*(s-b)*(s-c))*/



#include
#include

void main()
{
int a,b,c,p;
float s,area;
clrscr();
printf(“\n enter the 3 sides of a traingle:”);
scanf(“%d %d %d”,&a,&b,&c);
p=a+b+c;
s=p/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf(“\n area of traingle: %f”,area);
getch();

Lowercase to uppercase

#vpsinghrajput

#include
void main()
{
  char ch[20];
  int i=0;
  printf("Enter a string: ");
  while((ch[i]=getchar())!='\n')
      {
        if((ch[i]>='a')&&(ch[i]<='z'))
        {
            ch[i]=ch[i]-32;
        }
        i++;
      }
      i++;
      ch[i]='';
  printf("The uppercase string: ");
  printf(ch);
}
The output of this program will be,


Enter a string: vijay pratap singh rajput
The uppercase string: VIJAY PRATAP SINGH RAJPUT

Print I L U in C

#vpsinghrajput
#include
#include
void main()
{
    int i,j;
    clrscr();
    for(i=1;i<=3;i++)
    {
        printf("\n");
        for(j=1;j<=11;j++)
        {
            printf("I");
        }
    }
    for(i=1;i<=11;i++)
    {
        printf("\n");
        printf("    ");
        for(j=3;j>=1;j--)
        {
            printf("I");
         }
    }
    for(i=1;i<=3;i++)
    {
        printf("\n");
        for(j=1;j<=11;j++)
        {
            printf("I");
        }
    }
    for(i=1;i<=14;i++)
    {
         printf("\n\t\t\t\t");
         printf("");
         for(j=3;j>=1;j--)
         {
             printf("L");
         }
     }
     for(i=1;i<=3;i++)
     {
         printf("\n\t\t\t\t");
         for(j=1;j<=11;j++)
         {
             printf("L");
         }
     }
     for(i=1;i<=14;i++)
     {
         printf("\n\t\t\t\t\t\t\t\t");
         for(j=3;j>=1;j--)
         printf("U");
         printf("\t");
         for(j=3;j>=1;j--)
         printf("U");
      }
      for(i=1;i<=3;i++)
      {
         printf("\n\t\t\t\t\t\t\t\t");
         for(j=1;j<=11;j++)
         {
             printf("U");
         }
       }
       getch();
}

------------------------------------------------------------------------------------------------------
Output:-



Write a C program to find the factors of a given integer.

#vpsinghrajput


#include(stdio.h>
#include(conio.h)
void main( )
{
int no,x;
clrscr( );
printf("Enter the required number:");
scanf("%d",&no);
printf("\nThe factors are:");
for(x=1; x<=no; x++)
{
if(no%x==0)
printf("\n%d",x);
}
getch( );
}

Output:-
Enter the required number: 27
The factors are:
1
3
9
27

Write a C program to print all Armstrong numbers between 1 to 1000.

#vpsinghrajput


#include(stdio.h)
#include(conio.h)
int main( )
{
int no, temp, rem, sum;
clrscr( );
printf("Armstrong numbers between 1 and 1000 are:\n");
for(no=1; no<=1000; no++)
{
temp=no;
sum=0;
while(temp>0)
{
rem=temp%10;
sum=sum+(rem*rem*rem);
temp=temp/10;
}
if(no==sum)
printf("\n%d", no);
}
getch( );
return 0;
}

Output:
Armstrong numbers between 1 and 1000 are:
1
153
370
371
407

Write a C program to print the given alphabet pyramid.

#vpsinghrajput


A B C D E F G G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
-----------------------------------

#include
#include
int main( )
{
  int r,c,askey;
  clrscr( );
  
  for( r=7; r>=1; r-- )
  {
    askey=65;
    for(c=1; c<=r; c++ )
      printf("%2c", askey++ );
    askey--; 
    for(c=r; c>=1; c-- )
       printf("%2c", askey--);
   
   printf("\n");
  }
  getch();
  return 0;
}
 
Output:- 
A B C D E F G G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
Note:- 
'r' and 'c' means rows and columns .
'askey' variable is for disp. values.

Write a C program to print the given alphabet pyramid -2

#vpsinghrajput

A B C D E F G F E D C B A
  A B C D E F E D C B A
    A B C D E D C B A
      A B C D C B A
        A B C B A
          A B A
            A 


#include
#incldue
int main( )
{
  int r,c,askey,sp;
  clrscr( );
  
  for( r=7; r>=1; r-- )
  {
    for(sp=6; sp>=r; sp--)
        printf("  "); //2 spaces

    askey=65;
    for(c=1; c<=r; c++ )
      printf("%2c", askey++ );
    
    for(c=r-1; c>=1; c-- )
       printf("%2c", --askey);
   
   printf("\n");
  }
  getch();
  return 0;
}

Output:-
A B C D E F G F E D C B A
  A B C D E F E D C B A
    A B C D E D C B A
      A B C D C B A
        A B C B A
          A B A
            A 

//MIDTERM PROGRAMMING QUESTION

#vpsinghrajput


 #include
#include
void main()
{
clrscr();
char a[20],s;
int age,m;
printf("\nENTER THE NAME OF THE DRIVER : ");
gets(a);
printf("\nENTER THE AGE OF DRIVER   :   ");
scanf("%d",&age);
printf("\nENTER THE SEX OF THE DRIVER (M- MALE, F-FEMALE) : ");
scanf("%s",&s);
printf("\nENTER THE MARITAL STATUS OF THE DRIVER(0-MARRIED, 1-UNMARRIED): ");
scanf("%d",&m);
if(m==0)
printf("\nDRIVER IS INSURED");
else if(m==1 && s=='M' && age>=30)
printf("\nDRIVER IS INSURED");
else if(m==1 && s=='F' && age>=25)
printf("\nDRIVER IS INSURED");
else
printf("\nDRIVER IS NOT INSURED");
getch();}

ALGORITHM

·                      Start
·                     Declare a[20],s as character
·                     Declare m as an integer
·                                                                                     Write(“name of driver”)
·                     Read(“name of driver”)
·                                                                                     Write(“age of driver”)
·                     Read(“age of driver”)
·                                                                                     Write(“sex of the driver”)
·                     Read(“sex of driver”)
·                                                                                     Write(“marital status”)
·                     Read(“marital status”)
·                                                                                     if(age==0)
       if(m==1 && s=='M' && age>=30)
 if(m==1 && s=='F' && age>=25)
·                     Write(“driver insured”)
·                     Else
·                     Write(“driver not insured”)
·                     Stop


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