Wednesday, 8 April 2015

c program for transpose of matrix

write a c program for  transpose of matrix

/* c program for  transpose of matrix */
/*author:sai                         date:8-4-2015*/

#include <stdio.h>

int main()
{
   int m, n, i, j, matrix[10][10],transpose[10][10];

   printf("Enter the number of rows and columns of matrix\n");
   scanf("%d%d", &m, &n);

   printf("Enter the elements of matrix\n");

      for (i= 0; i < m; i++)
      for(j = 0; j < n; j++)
      scanf("%d",&matrix[i][j]);

      for (i = 0; i < m; i++)
      for( j = 0 ; j < n ; j++ )
      transpose[j][i] = matrix[i][j];

   printf("Transpose of entered matrix\n");

   for (i = 0; i < n; i++)
   {
   for (j = 0; j < m; j++)
   printf("%d\t",transpose[i][j]);
   printf("\n");
   }

   return 0;
}

output :

Tuesday, 7 April 2015

c program for to check wether the given number is prime or not

write a  c program for to check weather the given number is prime or not

/* c program for to check wether the given number is prime or not */
/* author:sai                                                        date:8-4-2015 */
#include<stdio.h>
int main()
{
int n,i,count=0;
printf("ENTER THE NUMBER TO CHECK PRIME OR NOT\n");
scanf("%d",&n);

for(i=2;i<n;i++)
if(n%i==0)
{
count++;
 
break;
}
if(count==0)
printf("prime number\n");
else
printf("not prime number\n");
}

output:


C Program for subtraction of two matrices

write a C Program for subtraction of two matrices

/* C Program for subtraction of two matrices*/
/*author:sai       date:7-4-2015 */
#include<stdio.h>
int main()
{
int a[10][10],b[10][10],c[10][10],i,j,m,n,p,q;
printf("enter order first matrix\n");
scanf("%d%d",&m,&n);
printf("enter elements of first matrix\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)

scanf("%d",&a[i][j]);
printf("enter order of second matrix");
scanf("%d%d",&p,&q);
printf("\n enter elements of second matrix\n");
for(i=0;i<p;i++)
for(j=0;j<q;j++)

scanf("%d",&b[i][j]);
for(i=0;i<m;i++)
for(j=0;j<q;j++)

{
c[i][j]=0;
c[i][j]=a[i][j]-b[i][j];
}

for(i=0;i<m;i++)
{
for(j=0;j<q;j++)

printf("\t%d",c[i][j]);
printf("\n");
}
}
output:



C Program for addition of two matrices

 write a C Program for addition of two matrices

/* C Program for addition of two matrices*/
/*author:sai       date:6-4-2015 */

#include<stdio.h>
int main()
{
int a[10][10],b[10][10],c[10][10],i,j,m,n,p,q;
printf("enter order first matrix\n");
scanf("%d%d",&m,&n);
printf("enter elements of first matrix\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)

scanf("%d",&a[i][j]);
printf("enter order of second matrix");
scanf("%d%d",&p,&q);
printf("\n enter elements of second matrix\n");
for(i=0;i<p;i++)
for(j=0;j<q;j++)

scanf("%d",&b[i][j]);
for(i=0;i<m;i++)
for(j=0;j<q;j++)

{
c[i][j]=0;
c[i][j]=a[i][j]+b[i][j];
}

for(i=0;i<m;i++)
{
for(j=0;j<q;j++)

printf("\t%d",c[i][j]);
printf("\n");
}
}

output:


c program for multiplication of two matrices

 write a c program for multiplication of two matrices
/* c program for multiplication of two matrices */
/*author:sai                                              date:7-4-2015 */

#include<stdio.h>
int main()
{
int a[10][10],b[10][10],c[10][10],m,n,p,q,i,j,k;
printf("enter order of first matrix\n");
scanf("%d%d",&m,&n);
printf("enter elements of first matrix\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("enter order of second matrix");
scanf("%d%d",&p,&q);
printf("enter elements of second matrix\n");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
if(n!=p)
printf("matrix multiplication is not posible\n");
else
for(i=0;i<m;i++)
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<p;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
printf("\t%d",c[i][j]);
printf("\n");
}
}
output :





Monday, 6 April 2015

C Program to find out the average of two numbers

write a C Program to find out the average of two numbers


/*Program to find out the average of two numbers*/

/*author:sai       date:6-4-2015 */

#include<stdio.h>

int main()

{

 int a,b;

 float c;

 printf("Enter Two numbers ");

 scanf("%d%d",&a,&b);

 c=(a+b)/2;

 printf("Average is = %f\n",c);

}

C program for sum of array elements

write a  c program for sum of array elements

/* c program for sum of array elements */
/*author:sai   date:6-4-2015 */

#include<stdio.h>

int main()
{
   int a[10];
   int i, sum = 0;
  

   printf("\nEnter 10 elements : ");

   for (i = 0; i < 10; i++)
  
   scanf("%d", &a[i]);



   for (i = 0; i < 10; i++)
   {
      sum = sum +a[i];
     
   }

   printf("The sum of array elements : %d\n", sum);
  
}

output:




C Program to find out the average of three numbers

 write a C Program to find out the average of three numbers

/*Program to find out the average of three numbers*/
/*author:sai       date:6-4-2015 */

#include<stdio.h>

int main()
{
 int a,b,c;
 float d;

 printf("Enter Three numbers ");
 scanf("%d%d%d",&a,&b,&c);
 d=(a+b+c)/3;
 printf("Average is = %f\ns",d);

}

output:




Saturday, 4 April 2015

c program to find the largest two numbers

 write a c program to find the largest two numbers

/*write a program to find the largest two numbers*/
/*author:sai        date:4-4-2015*/
#include <stdio.h>
int main()
{
   int a,b,c;
   printf("enter two values");
   scanf("%d%d",&a,&b);
   if(a>b)
 
   printf("a is big\n");
  
   else
  
    printf("b is big\n");



output:





Friday, 3 April 2015

shell script to print prime numbers upto a given Range

shell script to print prime numbers upto a given Range


clear
echo enter a range
read range
echo 2
j=3
while test $j -le $range
do
i=2
x=`expr $j - 1`
while test $i -le $x
do
if [ `expr $j % $i` -ne 0 ]
then
i=`expr $i + 1`
else
break
fi
done
if [ $i -eq $j ]
then
echo $j
fi
j=`expr $j + 1`
done



Thursday, 2 April 2015

write a shell script to check the given number is armstrong or not

write a shell script to check the given number is armstrong or not
clear
echo enter any number to check armstrong or not
read n
m=$n
sum=0
while [ $m != 0 ]
do
        y=`expr $m % 10`
        x=`expr $y \* $y \* $y`
        sum=`expr $sum + $x`
        m=`expr $m / 10`
done
if [ $sum -eq $n ]
then
        echo the given number is armstrong
else
        echo the given number is not armstrong
fi


output





write a shell script program to generate multiplication table

write a shell script program to generate multiplication table


clear
  echo "which number to generate multiplication table"
  read number
  i=1
  while [ $i -le 10 ]
  do
  echo " $number * $i =`expr $number \* $i ` "
  i=`expr $i + 1`
  done





output




Wednesday, 1 April 2015

c progaram to display the size of a data type

write a progaram to display the size of a data type
/* c  progaram to display the size of a data type */
/* author: sai      date:1-4-2015  */

# include <stdio.h>
int main()
{
   printf("size of short Int %d\n",sizeof(short int));
   printf("size of long Int %d\n",sizeof(long int));
   printf("size of float %d\n",sizeof(float));
   printf("size of double %d\n",sizeof(double));
   printf("size of char %d\n",sizeof(char));
}

output


c program to find area and circumfearence of a circle

 write a c program to find area and circumfearence  of a circle
/* c program to find area and circumfearence  of a circle*/

/* author: sai      date:1-4-2015 */

#incl#include<stdio.h>
int main()

{
   int radius;
   float PI = 3.14,area,ci;

   printf("\nEnter radius of circle");
   scanf("%d", &radius);

   area = PI * radius * radius;
   printf("Area of circle %f\n",area);

   ci = 2 * PI * radius;
   printf("Circumference %f\n",ci);
 }




c program to find area and peremeter of a square

 write a c program to find area and peremeter of a square
/*area and peremeter of a square*/
/* author: sai      date:1-4-2015 */

#include<stdio.h>
main()
{
    int s,area,perimeter;
    printf("enter side of a square");
    scanf("%d",&s);
    area = s*s;
    perimeter = 4*s;
    printf("area of the square %d is%d\n",s,area);
    printf("perimeter of the square %d is%d\n",s,perimeter);
}



c program to find area and perimeter of a rectangle

write a c program to find area and perimeter of a rectangle
/* To find area and perimeter of a rectangle*/
/* author: sai      date:1-4-2015 */

#include <stdio.h>
main()
{
   int l,b,area,perimeter;
   printf("enter l,b value");
   scanf("%d%d", &l,&b);
   area = l*b;
   printf("%d area of rectangle is\n", area);
   perimeter = 2 * (l + b);
   printf("%d perimeter of rectangle is\n", perimeter);
}




c program to find the area of a traingle

write a c program to find the area of a traingle

 
/* c program to find the area of a traingle*/
/* author: sai      date:30-3-2015 */

#include <stdio.h>
main()
{
   float l,h,area;
   printf("enter l,h values");
   scanf("%f%f", &l, &h);
   area = (l*h) / 2;
   printf("%f\n",area);
}



Monday, 30 March 2015

c program for conversion of uppercase to lower case to print ASCII value

 write a c program to convert of uppercase to lower case to print ASCII value
/*conversion of uppercase to lower case ASCII value*/
/*author:sai date:31-3-2015*/

#include<stdio.h>
main()
{
   char ch;
   printf("enter the charter in upper case\n");
   scanf("%c", &ch);
   printf("ASCII value%d\n", ch-32);
}



c program to check whether the given number is even or odd using goto statement

write a c program to check whether the given number is even or odd  using goto statement

/* c program to check whether the given  number is even or odd  using goto statement */

/* author: sai      date:30-3-2015 */

#include<stdio.h>
int main()
{
 int n;
 printf("\n enter number to check even or odd");
 scanf("%d",&n);
 if(n%2==0)
 goto even;
 else
 goto odd;
 even:printf("%d is even number\n",n);
 return;
 odd: printf("%d is odd number\n",n);
}



c program to print an integer that user entered using keyboard

write a c program to print an integer that user entered using keyboard

/* c program to print an integer that user entered using keyboard */

/* author: sai date:27-3-2015 */

#include

int main()
{
int n;

printf("Enter an integer\n");
scanf("%d", &n);

printf("Integer that you have entered is %d\n", n);

return 0;
}



c program to addition of two numbers

write a c program to addition of two numbers

/*  c program to addition of two numbers */

/* author:sai       date:27-3-2015 */

#include

int main()
{
int a,b,c;

printf("Enter two numbers for addition\n");
scanf("%d%d",&a,&b);

c = a + b;

printf("Sum of two numbers is = %d\n",c);

return 0;
}

Friday, 27 March 2015

Shell Script to Find Factorial of a Number

3)write a Shell Script to Find Factorial of a Number?
clear
echo "enter number"
read fact

ans=1
counter=0
while [ $fact -ne $counter ]
do
counter=`expr $counter + 1`
ans=`expr $ans \* $counter`
done
echo "Total of factorial is $ans"

Write a shell program to check whether a given string is palindrome or not


2) Write a shell program to check whether a given number is palindrome or not?
clear
echo "Enter the number you want?"
read num
m=$num
rev=0
while [ $num -gt 0 ]
do
r=`expr $num % 10`
rev=`expr $rev \* 10 + $r`
num=`expr $num / 10`
done
if [ $m = $rev ]
then
echo " $m is Palindrome"
else
echo " $m is not Palindrome"
fi


Write a shell script program to print the fibonacci series

1) Write a shell script program to print the fibonacci series


clear
echo "How many number of terms to be generated ?"
read n
x=0
y=1
i=2
echo "Fibonacci Series up to $n terms :"
echo "$x"
echo "$y"
while [ $i -lt $n ]
do
i=`expr $i + 1 `
z=`expr $x + $y `
echo "$z"
x=$y
y=$z
done