Write a C program to accept two strings str1 and str2 and compare them. if they are equal display their length. if str1 > str2 , convert str1 to uppercase and str2 to lowercase and display the strings and vice versa.


#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
void main()
{
char str1[30],str2[30],copy[60];
int cmp,length,ch;
clrscr();
            printf("\n Enter a string1 :");
            scanf("\n %s",&str1);
            printf("\n Enter a string2 :");
            scanf("\n %s",&str2);
            cmp=strcmp(str1,str2);
            if(strcmp(str1,str2)==0)
            {
            length=strlen(str1);
             printf("\n string are equals and length is %d",length);

             }
             if(strcmp(str1,str2)>0)
                        {
                        printf("\n string1 is greater");
                        printf("\n string1 in uppercase is %s",strupr(str1));
                        printf("\n string2 in lowercase is %s",strlwr(str2));
                         }
              else
                        {
                         printf("\n string2 is greater");
                        printf("\n string2 in uppercase is %s",strupr(str2));
                        printf("\n string1 in lowercase is %s",strlwr(str1));
             }

getch();
}
/* output

 Enter a string1 :maharashtra
 Enter a string2 :india

 string1 is greater
 string1 in uppercase is MAHARASHTRA
 string2 in lowercase is india */


Write a program, which accepts a character from the user and checks if it is an alphabet, digit or punctuation symbol. If it is an alphabet, check if it is uppercase or lowercase and then change the case.


#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("\n enter the character");
scanf("\n %c",&ch);

if(ch>=65 && ch<=90 || ch>=97 && ch<=122)
{
printf("\n the given character is alphabet");
if(ch>=65 && ch<=90)
{
 printf("\n character is uppercase");
}
else
{
   printf("\n character is lowercase");
 }
 }
 if(ch>=48 && ch<=57)
 {
printf(" the given character is digit");
}
if(ch>=58 && ch<=64 || ch>=91 && ch<=96)
{
printf("\n the given character is symbol");
 }
  getch();
  }
/* output

enter the character B

 the given character is alphabet
 character is uppercase */

Write a C program to display multiplication table up to 10 number.


#include <stdio.h>
int main()
{
    int n, i;
    printf("Enter an integer to find multiplication table: ");
    scanf("%d",&n);
    for(i=1;i<=10;++i)
    {
        printf("%d * %d = %d\n", n, i, n*i);
            }
            getch();;
}
/* iutput
Enter an integer to find multiplication table: 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50 */

Write a C program for multiplication of two matrices using dynamic memory allocation


#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void main()
{
int a[3][3],b[3][3],multi[3][3];
int i,j,k,row,col;

clrscr();
printf("\n enter the value of row")
scanf("\n %d",&row);
printf("\n enter the value of col")
scanf("\n %d",&col);
a[i][j]=(int)calloc(n,sizeof(int));

printf("\n enter first matrix-");

for(i=0;i<row;i++)
 {
 for(j=0;j<col;j++)
  {
  scanf("\n %d", &a[i][j]);
  }
 }
printf("\n enter the value of row")
scanf("\n %d",&row);
printf("\n enter the value of col")
scanf("\n %d",&col);
b[i][j]=(int)calloc(n,sizeof(int));

printf("\n enter second matrix-");

for(i=0;i<3;i++)
 {
 for(j=0;j<3;j++)
  {
  scanf("\n %d",&b[i][j]);
  }
 }
for(i=0;i<3;i++)
 {
 for(j=0;j<3;j++)
  {
   multi[i][j]=0;
   for(k=0;k<3;k++)
  {
  multi[i][j]=multi[i][j]+(a[i][k]*b[k][j]);
  }
 }
}
printf("\n the matrix multiplication is-");
for(i=0;i<3;i++)
 {
 for(j=0;j<3;j++)
  {
  printf("\t %d",multi[i][j]);
  }
 printf("\n");
}
getch();
}
/* Output
Enter first matrix-  1 2 3
                                  4 5 6
                                  7 8 9

Enter second matrix-  1 2 3
                                      4 5 6
                                      7 8 9

The matrix multiplication is-30    36    42
                                                 66    81    96
                                                 102  126  150  */