Write a c program to transpose a matrix.

#include<stdio.h>

#include<conio.h>

  main()

{

  int a[10][10],b[10][10];

  int i,j,m,n;

  clrscr();

  printf(" \n enter the row and column of matrix");

  scanf("\n %d%d",&m,&n);

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

  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++)

{

  printf("\n matrix =%d",a[i][j]);

}

}

  for(i=0;i<m;i++)

{

  for(j=0;j<n;j++)

{

  b[i][j]=0;

}

}

  for(i=0;i<m;i++)

{

  for(j=0;j<n;j++)

{

  b[i][j]=a[[j][i];

  printf("\n tranceposed matrix =%d",b[i][j]);

}

}

  return (0);

}



 output:-

  enter the row and column of matrix =3*3
  enter the element of matrix[a]=1,2,3,4,5,6,7,8,9
  matrix[a]=  1 2 3
                   4 5 6
                   7 8 9
  transpose of matrix[b]=  1 4 7
                                      2 5 8
                                      3 6 9

Write a c program to find whether the given point lies inside or outside of circile.

#include<stdio.h>
#include<conio.h>
  main()
{
   int x,y,r,x1,y1,p;
   clrscr();
   printf("\n enter the center of circle x and y");
   scanf("\n %d%d",&x,&y);
   printf("\n enter the radius of circle r');
   scanf("\n %d",&r);
   printf("\n enter the point x1 and y1");
   scanf("\n %d%d",&x1,&y1");
   p=(sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y)));
   if(p>r)
{
   printf("\n point lies out side of the circle =%d",p);
}
   else
{
   if(p<r)
{
   printf("\n point lies inside the circle =%d",p);
}
   else
{
   printf("\n point lies on the circle",p);
}
}
  return (0);
}

output:-
enter the center of circle x=0

enter the center of circle y=0
enter the radius of circle r=6
enter the point x1=3
enter the point y1=4
point lies inside the circle p=5 

write a c program to check leap year.

#include<stdio.h>
#include<conio.h>
main()
{
  int n;
clrscr();
printf("\n enter the year n");
scanf("\n %d",&n);
if(n%4!=0)
{
 printf("\n year is not leap %d",n);
}
else
{
 printf("\n year is leap %d",n);
}
return(0);
}

output:-
n=2020

year is leap

Write a program to swap two numbers without using temp variable.

#include<stdio.h>
#include<conio.h>
  main()
{
  int a,b;
  clrscr();
  printf("\n enter the number a and b")
  scanf("\n %d%d",&a,&b);
  a=a+b;
  b=a-b;
  a=a-b;
  printf("\n a=%d,b=%d",a,b);
  return (0);
}

output:-
 enter the number a=5
 enter the number b=9
 a=9
 b=5

Write a c program to reverse the number using array.

#include<stdio.h>
#include<conio.h>
  main()
{
  int arr[10],a,b,i,temp;
  clrscr();
  printf("\n enter the values of array");
  scanf("\n %d%d",&arr[a],arr[b]);
  temp=arr[a];
  arr[a]=arr[b];
  arr[b]=temp;
  printf("\n %d%d",arr[a],arr[b]);
  return (0);
}

 output:-
  enter the value of arr[a]=5
  enter the value of arr[b]=8
  [a]=8
  [b]=5 

Write a c program to print the numbers using array initialisation.

#include<stdio.h>
#include<conio.h>
  main()
{
  int arr[5]={1,2,3,4,5];
  int i;
  clrscr();
  for(i=0;i<5;i++)
{
  printf("\n%d",arr[i]);
}
  return (0);
}

output:-
 i=1

 i=2
 i=3
 i=4
 i=5

Write a c program to print a number using static function.

#include<stdio.h>
#include<conio.h>
  main()
{
  static int x;
  int i;
  clrscr();
  printf("\n enter the value of x");
  scanf("\n%d",&x);
  for(i=0;i<5;i++)
{
  printf("\n %d",x);
}
  return (0);
}

output:-

write a c program to print a pattern of alphabet letters.

#include<stdio.h>
#include<conio.h>
main()
{
  int i,j;
  clrscr();
  for(i=71;i>=65;i--)
{
  for(j=65;j<=i;j++)
{
  printf("%c",j);
}
  printf("\n");
}
  return (0);
}

output:-
ABCDEFG
ABCDEF
ABCDE
ABCD
ABC
AB
A



Write a function power ( a, b ), to calculate the value of a raised to b.

#include<stdio.h>
#include<conio.h>
int power(int a,int b);
int main()
{
int a,b,value;
printf("enter the value of a and b: ");
scanf("%d%d",&a,&b);
value=power(a,b);
printf("the value of a = %d raised to b = %d is %d",a,b,value);
getch();
return 0;
}
int power(int a,int b)
{
int i,value;
value=a;
for(i=1;i<b;i++)
{
value=value*a;
}
return value;
}


 output:-
enter the value of a=2
enter the value of b=5
raised value =2^5=32

Write a c program to find out the sum of series 1^2 + 2^2 + …. + n^2.

#include<stdio.h>
#include<conio.h>
  void main()
{
  int n,i;
  int sum=0;
  clrscr();
  printf("\n enter the number n");
  scanf("\n %d",&n);
  sum=(n*(n+1)*(2*n+1))/6;
  printf("\n sum of series =");
  for(i=1;i<=n;i++)
{
  if(i!=n)
{
  printf(" %d^2",i);
}
  else
{
  printf(" %d^2=%d",i,sum);
}
}
  return(0);
}

  output:-
  enter the number n=5
  sum of series =1^2+2^2+3^2+4^2+5^2=55

Write a program to find sum of cubes of given 'n' numbers.

#include<stdio.h>
#include<conio.h>
  main()
{
  int i,n;

  int sum=0;

  clrscr();

  printf("\n enter the number n");

  scanf("\n %d",&n);

  sum=pow(((n*(n+1))/2,2);

  printf("\n sum of series=");

  for(i=1;i<=n;i++)

{

  if(i!=n)

{

  printf("%d^3+",i);

}

  else

{

  printf("%d^3=%d",i,sum);

}

  return (0);

}



output:-

  enter the number n=5

  sum of series=1^3+2^3+3^3+4^3+5^3=225

Write a c Program to Convert Celcius to Fahrenheit.

#include<stdio.h>
#include<conio.h>
  main()
{
  int c;
  float f;
  clrscr();
  printf("\n enter the temprature in celsius");
  scanf("\n %d",&c);
  f=9/5*(c+32);
  printf("\n f =%f",f);
}
  return (0);
}

output:-
enter the temprature in celsius (c)=30

f=62.000










write a program to print Square of numbers by using loop.

#include<stdio.h>
#include<conio.h>
  main()
{
  int num,square;
  char another;
  clrscr();
  do
{
  printf("\n enter the number num");
  scanf("\n %d",&num);
  square=num*num;
  printf("\n square =%d",square);
  printf("\n want to enter another num y/n");
  scanf("\n %c",&another);
}
  while(another=='y');
   return (0);
}

output:-
enter the num=5
square=25
want to enter another num y/n
y
enter the num=10
square=100
want to enter another num y/n

Write a program to check whether a triangle is valid or not.

#include<stdio.h>
#include<conio.h>
  main()
{
  int x,y,z,sum=0;
  clrscr();
  printf("\n enter the angles x,y and z");
  scanf("\n %d%d%d",&x,&y,&z);
  sum=x+y+z;
  if(sum==180)
{
  printf("\n triangle is valid sum=%d",sum);
}
  else
{
  printf("\n triangle is not valid sum=%d",sum);
}
  return (0);
}

output:-
enter value of x=50
enter value of y=60
enter value of z=70
triangle is valid sum=180

write a c program an Arithmetic Progression series sum.

#include<stdio.h>
#include<conio.h>
  main()
{
  int i,n,d,a,tn,sum=0;
  clrscr();
  printf("\n enter the first term of the A.P.");
  scanf("\n %d",&a);
  printf("\n enter the difference of A.P.");
  scanf("\n %d",&d);
  printf("\n enter the total term in A.P.");
  scanf("\n %d",&n);
  sum=(n*(2*a+(n-1)*d))/2;
  tn=a+(n-1)*d;
  printf("\n sum of series =");
  for(i=a;i<=tn;i=i+d);
{
  if(i!=tn)
{
  printf("%d+",i);
}
  else
{
  printf("\n %d=%d",i,sum);
}
}
return (0);
}

output:-
first term of A.P. is  a=3

difference of A.P.is d=5
total term of A.P. is n=5
sum of the series= 3+8+13+18+23=65

Write a c program to find the largest of n numbers.

#include<stdio.h>
#include<conio.h>
  main()
{
  int x,y,z;
  clrscr();
  printf("\n enter the values of x,y and z');
  scanf("\n %d%d%d',&x,&y,&z);
  if((x>y)&&(x>z))
{
  printf("\n x=%d is  largest",x);
}
  else
{
  if((y>x)&&(y>z))
{
  printf("\n y=%d is  largest",y);
}
  else
{
  if((z>x)&&(z>y))
{
  printf("\n z=%d is  largest",z);
}
  else
{
  printf("\n x=%d,y=%d,z=%d all same",x,y,z);
}
}
  return (0);
}

 output:-
 x=50,y=77,z=30

 y=77 is  largest

write a c program for palindrome number.

#include<stdio.h>
#include<conio.h>
  main()
{
  int num,x,temp,sum;
  clrscr();
  printf("\n enter the number num");
  scanf("\n %d",&num);
  for(temp=num;num!=0;num=num/10)
{
  x=num%10
  sum=sum*10+x;
}
  if(temp==sum)
{
  printf("\n num is palindrome %d",temp);
}
  else
{
  printf("\n num is not palindrome %d',temp);
}
  return (0);
}

output:-
num=121

num is palindrome

write a c program to find sum of digits in a given number.

#include<stdio.h>
#include<conio.h>
main()
{
  int x,n,sum=0;
  clrscr();
  printf("\n enter the number n");
  scanf("\n %d",&n);
  for(x=1;x<=n;x++)
{
  sum+=x;
  printf("\n x=%d,sum=%d",x,sum);
}
  return (0);
}

write a program in c a given point(x,y) to find out if it lies on the x-axis,y-axis or on origin viz.(0,0),

#include<stdio.h>
#include<conio.h>
   main()
{
   int x,y;
   clrscr();
   printf("\n enter the points x and y');
   scanf("\n %d%d",&x,&y);
   if(x==0&&y==0)
{
   printf("\n points lies on origin");
}
   else
{
   if(x==0)
{
   printf("\n points lies on x-axis");
}
   else
{
   if(y==0)
{
   printf("\n points lies on y-axis");
}
   else
{
   printf("\n x=%d,y=%d",x,y);
}
}
}
   return (0);
}

output:-
x=12,y=0
points lies on y-axis

write a program in c to generate all combination of 1 and 2 using for loop.

#include<stdio.h>
#include<conio.h>
main()
{
  int i,j,k;
clrscr();
for(i=1;i<=2;i++)
{
 for(j=1;j<=2;j++)
{
 for(k=1;k<=2;k++)
{
 printf("\n i=%d,j=%d,k=%d",i,j,k);
}
}
}
return (0);
}

output:-
i=1,j=1,k=1
i=1,j=1,k=2
i=1,j=2,k=1
i=1,j=2,k=2
i=2,j=1,k=1
i=2,j=1,k=2
i=2,j=2,k=1
i=2,j=2,k=2

write a program in c to printf the multiplication table of the number enter by the user.

#include<stdio.h>
#include<conio.h>
main()
{
   int i,num,mult;
   clrscr();
   printf("\n enter the num");
   scanf("\n%d",&num);
   for(i=1;i<=num;i++)
{
   mult=num*i;
   printf("\n  num=%d of mult=%d",num,mult);
}
   return (0);
}


output:-

enter the num=5

num=1 of mult=5
num=2 of mult=10
num=3 of mult=15
num=4 of mult=20
num=5 of mult=25

write a program in c to print the numbers is prime or not.

#include<stdio.h>
#include<conio.h>
main()
{
  int i,num;
  clrscr();
printf("\n enter the number num");
scanf("\n %d",&num);
  i=2;
  while(i<=num-1)
{
   if(num%2==0)
{
   printf("\n num is not prime");
  break;
}
  i++;
}
  if(i==num)
{
  printf("\n num is prime");
}
  return (0);
}


output:-
*enter the num-23

num is prime.
*enter the num-118
num is not prime.

write a program in c a five-digit number is input through the keyboard to reverse the number.

#include<stdio.h>
#include<conio.h>
main()
{
 int a,b;
clrscr();
  printf("\n enter the a number a");
  scanf("\n %d",&a);
  while(a>0)
{
   b=a%10;
   printf("\n %d", b);
   a=a/10;
}
return (0);


output:-
 a=12345

 b=54321

write a program in c of the lower triangle of natural numbers.

#include<stdio.h>
#include<conio.h>
main()
{
 int i,j;
clrscr();
 for(i=9;i>=1;i--)
{
  for(j=1;j<=9;j++)
{
  printf("%d",j);
}
  printf("\n");
}
return (0);
}


output:-
123456789

12345678
1234567
123456
12345
1234
123
12
1