Wednesday, 20 November 2013

C-Program to Check the matrix is orthogonal or not

know about orthogonal of a matrix : http://en.wikipedia.org/wiki/Orthogonal_matrix



#include<stdio.h>
#include<conio.h>
main()
{
    int m,n,i,j,k,sum=0;
    int a[20][20],t[20][20],p[20][20];
  printf("Enter the number of rows and columns(order)\t");
    scanf("%d%d",&m,&n);
    printf("Enter the elements of matrix\t");
for(i=0;i<m;i++)
    for(j=0;j<n;j++)
        scanf("%d",&a[i][j]);
  for(i=0;i<m;i++)
    {
      for(j=0;j<n;j++)
      {
          t[j][i]=a[i][j];
      }
    }
for(i=0;i<m;i++)
    {
      for(j=0;j<n;j++)
      {
          for(k=0;k<n;k++)
          sum=sum+a[i][k]*t[k][j];
    p[i][j]=sum;
        sum=0;
      }
    }
  for(i=0;i<m;i++)
    {
      for(j=0;j<m;j++)
        {
          if(i==j)
            if(p[i][j]!=1)
                   break;
else
            if (p[i][j]!=0)
                   break;
        }
       if(j!=m)
          break;
    }
    if(i!=m)
      printf("Given matrix is not orthogonal.\n");
    else
      printf("Given matrix is orthogonal.\n");
}



sakoncepts.blogspot.in
output

C-Program to Find Saddle point of a Matrix


know about saddle point in a matrix : http://en.wikipedia.org/wiki/Saddle_point






#include <stdio.h>
main() 
{
int i,j,k,n,min,max,a[20][20],p[10][10];
printf("Enter the order\t");
    scanf("%d",&n);
printf("Enter the elements\t");
    for(i=0;i<n;i++) 
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
    printf("Matrix is\n");
    for(i=0;i<n;i++) 
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
for(i=0;i<n;i++)
{
        min=a[i][0];
      for(j=0;j<n;j++) 
{
            if(min>=a[i][j]) 
{
              min=a[i][j];
                p[0][0]=i;
                p[0][1]=j;
            }
        }
j=p[0][1];
        max=a[0][j];
        for(k=0;k<n;k++) 
{
        if(max<=a[k][j]) 
{
              max=a[i][j];
          p[1][0]=k;
              p[1][1]=j;
            }
      }
if(min==max) 
{
      if(p[0][0]==p[1][0]&&p[0][1]==p[1][1]) 
printf("Saddle point is %d at the position (%d,%d)\n",max,p[0][0],p[0][1]);
        }
  }
}



sakoncepts.blogspot.in
output

C-Program to Find the Prime Numbers in the diagonals of matrix and replace its value to its next number

#include<stdio.h>
main()
{
int a[50][50],m,n,i,j,b[20],p[20],q=0,k,c[20],r[20],s[20];
  printf("Enter no. of rows and columns(order)\t");
  scanf("%d%d",&m,&n);
  printf("Enter the elements of matrix:\n");
  if(m==n)
  {
    for(i=0; i<m; i++)
    for(j=0; j<n; j++)
          scanf("%d",&a[i][j]);
  printf("matrix representation of above elemnts is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}

for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
{
for(k=2;k<a[i][j];k++)
{
if(a[i][j]%k==0)
break;
}
if(a[i][j]==k)
{
b[q]=a[i][j];
p[q]=i+1;
q++;
a[i][j]=a[i][j]+1;
}
}
}
}
q=0;
for(i=0,j=n-1;i<m||j>=0;i++,j--)
{
for(k=2;k<a[i][j];k++)
if(a[i][j]%k==0)
break;
if(a[i][j]==k)
{
c[q]=a[i][j];
r[q]=i+1;
s[q]=j+1;
q++;
a[i][j]=a[i][j]+1;
}
}
printf("The prime numbers in the diagonals are \n");
for(i=0;i<q;i++) 
printf("%d at the position %d%d\n",b[i],p[i],p[i]);
for(i=0;i<q;i++) 
printf("%d at the position %d%d\n",c[i],r[i],s[i]);
printf("\n\nnew matrix after modification is \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}   
}  
else
  printf("This program is only applicable to square matrices!!!");
 
}


sakoncepts.blogspot.in
output




C-Program to Check and print the Prime numbers in the diagonals of a matrix

#include<stdio.h>
main()
{
int a[50][50],m,n,i,j,b[20],p[20],q=0,k,c[20],r[20],s[20];
  printf("Enter no. of rows and columns(order)\t");
  scanf("%d%d",&m,&n);
  printf("Enter the elements of matrix:\n");
  if(m==n)
  {
    for(i=0; i<m; i++)
    for(j=0; j<n; j++)
          scanf("%d",&a[i][j]);
  printf("matrix representation of above elemnts is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}

for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
{
for(k=2;k<a[i][j];k++)
{
if(a[i][j]%k==0)
break;
}
if(a[i][j]==k)
{
b[q]=a[i][j];
p[q]=i+1;
q++;
}
}
}
}
q=0;
for(i=0,j=n-1;i<m||j>=0;i++,j--)
{
for(k=2;k<a[i][j];k++)
if(a[i][j]%k==0)
break;
if(a[i][j]==k)
{
c[q]=a[i][j];
r[q]=i+1;
s[q]=j+1;
q++;
}
}
printf("The prime numbers in the diagonals are \n");
for(i=0;i<q;i++) 
printf("%d at the position %d%d\n",b[i],p[i],p[i]);
for(i=0;i<q;i++) 
printf("%d at the position %d%d\n",c[i],r[i],s[i]);
}  
else
  printf("This program is only applicable to square matrices!!!");
 
}



sakoncepts.blogspot.in
output




C-Program to Interchange the diagonals of a matrix

#include<stdio.h>
main()
{
int a[50][50],m,n,i,j,d1=0,d2=0,t;
  printf("Enter no. of rows and columns(order)\t");
  scanf("%d%d",&m,&n);
  printf("Enter the elements of matrix:\n");
  if(m==n)
  {
    for(i=0; i<m; i++)
    for(j=0; j<n; j++)
          scanf("%d",&a[i][j]);
  printf("matrix representation of above elemnts is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
for(i=0,j=n-1;i<m||j>=0;i++,j--)
{
t=a[i][i];
a[i][i]=a[i][j];
a[i][j]=t;
}
printf("\n\nthe new matrix after interchanging is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
}
else
  printf("This program is only applicable to square matrices!!!");
 
}




sakoncepts.blogspot.in
output



C-Program to find the diagonal Sum of a Matrix

#include<stdio.h>
main()
{
int a[50][50],m,n;
  int i,j,d1=0,d2=0;
  printf("Enter no. of rows and columns(order)\t");
  scanf("%d%d",&m,&n);
  printf("Enter the elements of matrix:\n");
  if(m==n)
  {
    for(i=0; i<m; i++)
    for(j=0; j<n; j++)
          scanf("%d",&a[i][j]);
  printf("matrix representation of above elemnts is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
for(i=0,j=n-1;i<m||j>=0;i++,j--)
    {
        d1=d1+a[i][i];
        d2=d2+a[i][j];
    }
    printf("\nFirst diagonal's SUM\t%d",d1);
    printf("\nSecond diagonal's SUM\t %d",d2);
  }
  else
  printf("This program is only applicable to square matrices!!!");
 
}



sakoncepts.blogspot.in
output

C-program to Find the Diagonal sum of a square matrix

#include<stdio.h>
main()
{
int a[50][50],o,i,j,d1=0,d2=0;
  printf("Enter the order of square matrix\t");
  scanf("%d",&o);
  printf("Enter %d elements of the matrix:\n",(o*o));
  for(i=0;i<o;i++)
    for(j=0;j<o;j++)
          scanf("%d",&a[i][j]);
  printf("matrix representation of above elemnts is\n");
for(i=0;i<o;i++)
{
for(j=0;j<o;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
for(i=0,j=o-1;i<o||j>=0;i++,j--)
    {
    d1=d1+a[i][i];
    d2=d2+a[i][j];
    }
    printf("\nFirst diagonal's SUM\t%d",d1);
    printf("\nSecond diagonal's SUM\t%d",d2);
}  



sakoncepts.blogspot.in
output

C-Program to check whether a word is Palindrome

#include<stdio.h>
#include<string.h>
main()

char a[100],b[100]; 
int i,k; 
printf("Enter the string\t"); 
gets(a); 
k=strlen(a)-1; 
for(i=0; i<strlen(a); i++)

b[i]=a[k]; 
k--; 

b[strlen(a)]='\0'; 
k=strcmp(a,b); 
if (k==0) 
printf("%s is palindrome",a); 
  else 
printf("%s is not palindrome",a);  


sakoncepts.blogspot.in
output


Tuesday, 19 November 2013

C-Program to Generate prime Number Series

#include<stdio.h>
main ()
{
int i=2,n,r;
printf("enter the number till the prime numbers needed\t");
scanf("%d",&n);
printf("prime numbers are\t");
for(r=1;r<=n;r++)
{
for(i=2;i<r;i++)
{
if(r%i==0)
break;
}
if(r==i)
printf("%d\t",r);
}
}



sakoncepts.blogspot.com
output

C-program to Generate Fibonacci series

#include<stdio.h>
main ()
{
int n,i,a=0,b=1,c;
printf("No.of terms needed in the series\t");
scanf("%d",&n);
printf("elements are \t");
for(i=0;i<n;i++)
{
if(i<=1)
c=i;
else
{
c=a+b;
a=b;
b=c;
}
printf("%d\t",c);
}
}


sakoncepts.blogspot.com
output


C-Program to Generate series of 0 2 1 3 1 5 2 8 3 12 5 17 8 23 13 30 21 . . . . .

#include<stdio.h>
main ()
{
int j=0,i=2,n,r=2,p[100]={0},f[100]={0},a=0,b=1,c;
printf("enter the Number of terms needed\t");
scanf("%d",&n);
for(i=0;i<n;i++)
{
r=r+i;
p[j]=r;
j++;
}  
for(i=0;i<n;i++)
{
if(i<=1)
c=i;
else
{
c=a+b;
a=b;
b=c;
}
f[i]=c;
}
printf("The elements are \t");
if(n%2==0)
for(i=0;i<(n/2);i++)
printf("%d\t%d\t",f[i],p[i]);
  else
{
for(i=0;i<(n/2);i++)
printf("%d\t%d\t",f[i],p[i]);    
printf("%d\t",f[i]);
}
}



sakoncepts.blogspot.com
output

C-Program to Generate the series 0 2 1 3 1 5 2 7 3 11 5 13 8 17 13 19 21 23 34 29. . . . .

#include<stdio.h>
main ()
{
int j=0,i=2,n,r,p[100]={0},f[100]={0},a=0,b=1,c;
printf("enter the Number of terms needed\t");
scanf("%d",&n);
for(r=1;r<=(2*n);r++)
{
for(i=2;i<r;i++)
{
if(r%i==0)
break;
}
if(r==i)
{  
p[j]=r;
j++;
}  
}
for(i=0;i<n;i++)
{
if(i<=1)
c=i;
else
{
c=a+b;
a=b;
b=c;
}
f[i]=c;
}
printf("The elements are \t");
if(n%2==0)
for(i=0;i<(n/2);i++)
printf("%d\t%d\t",f[i],p[i]);
  else
{
for(i=0;i<(n/2);i++)
printf("%d\t%d\t",f[i],p[i]);    
printf("%d\t",f[i]);
}
}




sakoncepts.blogspot.com
output

C-Program to Find the Prime digits in a Given Number

#include<stdio.h>
#include<stdlib.h>
main ()
{
int n,i=0,j=0,d,r,a[50]={0},b[50]={0},k;
printf("Enter the number\t");
scanf("%d",&n);
if(n==0)
{
printf("0 is neither prime nor composite");
exit(0);
}
i=0;
d=n;
while(n>0)
{
r=n%10;
a[i]=r;
i++;
n=n/10;
}
for(k=0;k<i;k++)
{
for(r=2;r<i;r++)
  if(a[k]%r==0)
break;
if(a[k]==r)
{
b[j]=a[k];
j++;
}
}
printf("The prime numbers are\t");
for(i=0;i<j+1;i++)
printf("%d\t",b[i]);
}



sakoncepts.blogspot.com
output

C-Program to find the Vowels in a string and convert it into Capital letters

#include<stdio.h>
#include<ctype.h>
#include<string.h>
main ()
{
char a[50];
int l,i,p=0;
printf("Enter the string\t");
scanf("%s",a);
l=strlen(a);
printf("vowels in the given string are at positions\n");
for(i=0;i<l;i++)
{
if((a[i]==97)||(a[i]==101)||(a[i]==105)||(a[i]==111)||(a[i]==117)||(a[i]==65)||(a[i]==69)||(a[i]==73)||(a[i]==79)||(a[i]==85))
{
p=i+1;
printf("%d is %c\n",p,a[i]);
}
switch(a[i])
{
case 97:
a[i]=65;
break;
case 101:
a[i]=69;
break;
case 105:
a[i]=73;
break;
case 111:
a[i]=79;
break;     
case 117:
a[i]=85;
break;
default:
break;     
}
p=0;
}
printf("The new string is\t%s",a);
}



sakoncepts.blogspot.com
output