Posts

Showing posts with the label C Programming WITH INPUT AND OUTPUT

c program to multiplication of two 3*3 matrices

     /* c program to multiplication of two 3*3 matrices*/ #include<stdio.h> #include<conio.h> void main() {      int m1[3][3],m2[3][3],prod[3][3];      int i,j,k;      clrscr();       printf("enter the first matrix : \n");         for(i=0;i<3;i++)           for(j=0;j<3;j++)            scanf("%d",&m1[i][j]);      printf("enter 2nd matrix : \n");          for(i=0;i<3;i++)            for(j=0;j<3;j++)             scanf("%d",&m2[i][j]); /* multiplication of matrix */       for(i=0;i<3;i++)      for(j=0;j<3;j++)  ...

c program to subtract two 3*3 matrices

/*c program to subtract two 3*3 matrices*/ #include<stdio.h> #include<conio.h> void main()   {     int m1[3][3],m2[3][3],msub[3][3];     int i,j;     clrscr();     printf("type in 9 integer number of first matrix:\n");     for(i=0;i<3;++i)        for(j=0;j<3;++j)                    scanf("%d",&m1[i][j]);     printf("\n type in 9 integer number of first matrix:\n");     for(i=0;i<3;++i)        for(j=0;j<3;++j)                    scanf("%d",&m2[i][j]); /*matrix subtraction proceeds as follows...*/    for(i=0;i<3;++i)    for(j=0;j<3;++j)        msub[i][j]=m1[i][j]-m2...

c program to add two 3*3 matrices

/*c program to add two 3*3 matrices*/ #include<stdio.h> #include<conio.h> void main()   {     int m1[3][3],m2[3][3],madd[3][3],msub[3][3];     int i,j;     clrscr();     printf("type in 9 integer number of first matrix:\n");     for(i=0;i<3;++i)        for(j=0;j<3;++j)                    scanf("%d",&m1[i][j]);     printf("\n type in 9 integer number of first matrix:\n");     for(i=0;i<3;++i)        for(j=0;j<3;++j)                    scanf("%d",&m2[i][j]); /*matrix addition proceeds as follows...*/     for(i=0;i<3;++i)       for(j=0;j<3;++j)      ...

to arrange number descending using bubble sort technique

/*to arrange number descending using bubble sort technique*/ #include<stdio.h> #include<conio.h> void main() {   int num[10];   int loop,i;   int last=10;   int exchange;   int temp;   clrscr();   printf("enter the 10 number\n");   for(i=0;i<10;++i)    scanf("%d",&num[i]); for(loop=0;loop<9;++loop) {      exchange=0;      for(i=0;i<(last-1);i++)                   if(num[i]>num[i+1])                     {                       temp=num[i];                       num[i]=num[i+1];     ...

to arrange number ascending using bubble sort techniqu

                  /*to arrange number ascending using bubble sort technique*/ #include<stdio.h> #include<conio.h> void main() {   int num[10];   int loop,i;   int last=10;   int exchange;   int temp;  clrscr();  printf("enter the 10 number\n");  for(i=0;i<10;++i)    scanf("%d",&num[i]);  for(loop=0;loop<9;++loop) {     exchange=0;      for(i=0;i<(last-1);i++)                  if(num[i]<num[i+1])                     {                       temp=num[i];                   ...

sum and average of 3 numbers

/*sum and average of 3 numbers*/ #include <stdio.h> #include <conio.h> void main() { int n1,n2,n3; float sum,average; printf("enter 3 integer numbers\n"); sum=(n1+n2+n3); average=sum/3; printf("The sum of 3 numbers is=%f\n,sum); printf=("The average of numbers=%f/n",average); getch() } out put please enter 3 integer numbers 12 25 33 sum of 3 numbers=70.000000 avg of 3 numbers=23.333334

Largest of 3 number

/*Largest of 3 number */ #include<stdio.h> #include<conio.h> void main() { int a,b,c; printf("enter the 3 numbers\n"); scanf("%d %d %d",&a,&b,&c); if(a>b && a>c) printf("a is greater\n"); else if(b>a && b>c) printf("b is greater"); else printf("c is greater"); getch(); } out put enter the 3 numbers 9 7 20 c is greater

To find whether a number is prime or not

#include<stdio.h> #include<conio.h> main() {    int i,number,remainder,interval;    clrscr();  /*program to test the prime property of a given number*/  printf("type in the number to be tested\n");  scanf("%d",&number);  interval=number/2;  for(i=2; i<=interval; ++i)     {     remainder=number%i;     if(remainder==0)     break;     }   if(remainder!=0)     printf("given number %d is a PRIME NUMBER\n",number);   else     printf("given number %d is not a PRIME NUMBER\n",number);   } OUTPUT type in the number to be tested 43 given number 43 is a PRIME NUMBER

finding the roots of the quadratic equation using switch-statement

#include<stdio.h> #include<conio.h> void main() { int option; float a,b,c,d; float root1,root2,r1,r2; clrscr(); printf("enterthe value of a,b,c\n"); scanf("%f%f%f",&a,&b,&c); if (a==0||b==0||c==0) { printf("\n error_we cannot analyse"); exit(); } d=(b*b-4*a*c); if(d>0)  option=1; else  if(d<0)  option=2; else  option=3; switch(option) { case1: printf("roots are real & distinct\n"); root1=(-b+sqrt(d))/2*a; root2=(-b-sqrt(d))/2*a; printf("\n root1=%f root2=%f\n",root1,root2); break; case 2: printf("\n roots are imaginary & complex\n"); r1=-b/2*a; r2=sqrt(abs(d))/2*a; printf("root1=%f+%f\n",r1,r2); case 3: printf("\n roots are real & equal\n"); root1=root2=-b/2*a; printf("root1=%f\n,root2=%f\n",root1,root2); break; } getch(); } OUTPUT enter the value of a,b,c 22,33,44  roots are imaginary & complex...

whether number is even or odd

/*whether number is even or odd*/ #include<stdio.h> #include<conio.h> void main() { int num,remainder; clrscr(); printf("enter the number\n"); scanf("%d",&num); remainder=num%2; if (remainder==0) printf("the number is even\n"); else printf("the number is odd\n"); getch(); } OUTPUT enter the number 121  the number is odd

sum of digit of given number

/*sum of digit of given number*/ #include<stdio.h> #include<conio.h> void main() { int number,sum=0,r; clrscr(); printf("enter the number\n"); scanf("%d",&number); do { r=number%10; sum=sum+r; number=number/10; } while(number!=0); printf("sum of digit is=%d\n",sum); getch(); } OUTPUT enter the number 123 sum of digit is=6