pages

Sunday, 11 April 2021

C-Program to arrange the 10 natural numbers in ascending order || c-programming

 write a program in c-language to arrange the 10 natural numbers in ascending order.

In this program, we will sort the given array in ascending order and  user will enters the 10 natural number and this 10 natural number are arrange smallest to largest number.

#include<stdio.h>
#include<conio.h>
void main()
{
    int a[10],i,j,temp;
    printf("enter the 10 number\n");
    for(i=1;i<=10;i++)
        scanf("%d",&a[i]);
    for(i=1;i<=10;i++)
    printf("%d ",a[i]);
    for(i=1;i<=10;i++){
        for(j=i+1;j<=10;j++){
            if(a[i]>a[j]){
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
    printf("\nascending order are follow :\n");
    for(i=1;i<=10;i++)
        printf(" %d",a[i]);
    getch();
}


output are follow:-







Saturday, 10 April 2021

write a program for which user choose their options which given options in c-programming.

 Q.NO  write a program for which user choose their options which has following options
   1.odd or even  2.greatest of two number  3.triangle are valid or not
 4. +ve or -ve   5. exit    enter your option

#include<stdio.h>

#include<conio.h>

void main()
{
   int a,b,c,option;
   while(1){
         printf(" 1.odd or even");
         printf("\n 2.greatest of two number");
         printf("]n 3.triangle are valid or not");
         printf("\n 4. +ve or -ve");
         printf("\n5. exit");
         printf("\n enter your option");
         scanf("%d",&option);
         switch(option)
         {
         case 1:
                  printf("\n enter a number");
                  scanf("%d",&a);
                  if(a%2==0)
                           printf("\n even number");
                  else
                           printf("odd number");
                  break;
         case 2:
                  printf("\n enter two numbers");
                  scanf("%d %d",&a,&b);
                  if(a>b)
                           printf("\n greatest number is %d",a);
                  else
                           printf("\n greatest number is %d",b);
                  break;
         case 3:
                  printf("\n triangle is valid or not");
                  scanf("%d %d %d",&a,&b,&c);
                  if(a+b+c==180)
                           printf("\n triangle is valid");
                  else
                           printf("\n triangle is not valid");
                  break;
         case 4:
                  printf("\n +ve or -ve");
                  scanf("%d",&a);
                  if(a>0)
                           printf("+ve number");
                  else
                           printf("-ve number");
                  break;
         case 5:
                  exit(0);
                  default:
                  printf("\n wrong option");
                  break;
         }
   }
    getch();
}

If the three sides of the triangle is entered form the keyboard, write a program to check weather the triangle is equilateral or isosceles or scalene triangle.

 Q.no If the three sides of the triangle is entered  form the keyboard, write a program  to check weather the triangle is equilateral or isosceles or scalene triangle.

In this program ,we will making a program by which user entering the values of the sides of a triangle and check weather the triangle is equilateral or isosceles or scalene triangle.
As we know that if all the sides of the triangle is equal than it is equilateral triangle
and if only two sides of a triangle is equal than isosceles triangle , and if all sides are different then the triangle is scalene triangle.


#include<stdio.h>
#include<conio.h>
void main()
{
   int a,b,c;
   printf("enter the values of sides of a triangle");
   scanf("%d %d %d",&a,&b,&c);
   if(a==b&&b==c&&a==c)
         printf("\n equilateral triangle");
   else{
         if(b==c||a==b||a==c)
              printf("\n isosceles triangle");
         else
             printf("\n scalane triangle");
   }
    getch();
}


output:- enter the values of the sides of a triangle a=3 b=5 c=3

                  the triangle is isosceles triangle

program to takes two times "hour and minute" time by the user and add them and print in hour and minute time in c-programming.

 program to takes two times "hour and minute" time  by the user and add them and print in hour and minute time in c-programming.

here, we will entering the values of times by the user at two times and add them and print. 

suppose t1= 2h 36 min  t2 = 5h 56 min 

then h= 2h +5h               and m= 36 min+56min

           h= 7h                            m= 92min

 total times = h+ (92/60) :(92%60)min

total time    = 7h + 1h : 32min

total times= 8h : 32 min

                       

#include<stdio.h>
#include<conio.h>
void main()
{
   int  h1,h2,h3,h,m,m1,m2,m3;
   printf("enter the vales of the first time");
   scanf("%d %d",&h1,&m1);
   printf("\nenter the values of the second times");
   scanf("%d %d",&h2,&m2);
   m3=m1+m2;
   h=m3/60;
   m=m3%60;
   h3=h1+h2+h;
   printf("\nthe hour time is %d and minute time is %d",h3,m);
   getch();
}


output:  












program to calculate the addition of the two matrices in c-programming.

 Q.no program to calculate the addition of the two matrices in c-programming

In this program, we will adding two matrices in c-language of the same order 3x3. i.e the number of rows and column are same.


 In this program user is asked to enter the values of the first and the last matrices of 3x3 order then the program return the output.


#include<Stdio.h>
#include<conio.h>
main()
{
    int a[3][3],b[3][3],c[3][3],i,j;
    printf("enter the value of the first matrices");
    for(i=0;i<=2;i++)
        for(j=0;j<=2;j++)
            scanf("%d",&a[i][j]);
    printf("enter the value of the second matrices");
    for(i=0;i<=2;i++)
        for(j=0;j<=2;j++)
           scanf("%d",&b[i][j]);
    printf("the sum of the two matrices \n");
    for(i=0;i<=2;i++)
    {
        for(j=0;j<=2;j++)
        {
            c[i][j]=a[i][j]+b[i][j];
            printf("%d ",c[i][j]);
        }
        printf("\n");
    }
    getch();
}

output are follow:- 














program to calculate the multiple of the two matrix in c-programing.| c-programming languages

 Q.no Program to calculate the multiple of the two matrix in c-language

In this program, we will calculate the product of the two matrices (two -dimensional arrays).
user print the values of the two matrices of order 3x3. i.e

Multiple of two matrices, the number of columns of the first matrix should be equal to the number of the second matrix. 


 #include<stdio.h>
#include<conio.h>
void main()
{
    int a[3][3],b[3][3],c[3][3],i,j,k;
    printf("enter the values of the first matrices");
    for(i=0;i<3;i++)
        for(j=0;j<3;j++)
        scanf("%d",&a[i][j]);
    printf("enter the values of the second matrices");
    for(i=0;i<3;i++)
        for(j=0;j<3;j++)
        scanf("%d",&b[i][j]);
    printf("the multiple of the matrices is \n");
    for(i=0;i<3;i++){
        for(j=0;j<3;j++)
        {
            c[i][j]=0;
            for(k=0;k<3;k++){
                c[i][j]=c[i][j]+a[i][k]*b[k][j];
            }
             printf("%d ",c[i][j]);
        }
        printf("\n");
    }
    getch();
}


output are follow:- 

                   
               















c-program to swap the two number without using the third variables.

 program to swap the two number without using third variables in c-programming?

program to swap two numbers without third variable in c program.

we will swap/exchange of  two numbers without using third variable are given below:


#include<stdio.h>
#include<conio.h>
main()
{
    int a,b;
    printf("enter two number");
    scanf("%d %d",&a,&b);
    printf("before swapping a=%d and b=%d",a,b);
    a=a+b;
    b=a-b;
    a=a-b;
    printf("after swapping a=%d and b=%d",a,b);
    getch();
}

output:-  before swapping a=3  and b=5
             after swapping a=5 and b=3