Showing posts with label Cprogramming. Show all posts
Showing posts with label Cprogramming. Show all posts

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:





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;
}