Skip to main content

Posts

777

HTML <p&gt#include int main() { int i,j,n,a[100],temp; printf("enter the number of elements"); scanf("%d",&n); printf("enter the elements\n"); for(i=0;i scanf("%d",&a[i]); for(i=0;i { for(j=0;j { if(a[j]>a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } printf("sorted arry\n"); for(i=0;i printf("%d\t",a[i]); return 0; } </p>

Taylor series

#include<stdio.h> #include<stdlib.h> #include<math.h> int main() {     int ch,i;     float num,den,x,degree,sum=0,term;     printf("enter 1 for sin(x)\n enter 2 for cos(x)\n");     scanf("%d",&ch);     printf("enter the degree");     x=(degree*3.14)/180.0;     switch(ch)     {         case1:num=x;         den=1;         i=2;         break;         case2:num=1;         den=1;         i=1;         break;         default:printf("enter the proper choice\n");         exit(0);     }     do     {         term=num/den;         num=-num*x*x;         den=den*i*(i+1);         sum=sum+term; ...

bubble sort

program #include<stdio.h> int main() {     int i,j,n,a[100],temp;     printf("enter the number of elements");     scanf("%d",&n);     printf("enter the elements\n");     for(i=0;i<n;i++)     scanf("%d",&a[i]);     for(i=0;i<n-1;i++) {     for(j=0;j<n-i-1;j++) {     if(a[j]>a[j+1]) {     temp=a[j];     a[j]=a[j+1];     a[j+1]=temp; } } } printf("sorted arry\n"); for(i=0;i<n;i++) printf("%d\t",a[i]); return 0; }      Algorithm: BubbleSort Start read n for i= 0 to n-1  read a[i]  for i=0 to n-1  for j=0 to n-i-1  if (a[j] > a[j+1])  temp = a[j] a[j] = a[j+1] a[j+1] = temp  for i=0 to n-1 print a[i] Stop

Matrix Multiplication

#include<stdio.h> #include<stdlib.h> void main() { int a[10] [10],b[10] [10],c[10] [10],i,j,k,m,n,p,q; printf("enter the order of the matrix A\n"); scanf("%d%d",&m,&n); printf("enter the order of the matrix B\n"); scanf("%d%d",&p,&q); if(n!=p) {     printf("matrix multiplication is not possible\n");     exit(0); } printf("enter the elements of A\n"); for(i=0;i<m;i++) {     for(j=0;j<n;j++)     {         scanf("%d",&a[i][j]);     } } printf("enter the elements of B\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;         for(k=0;k<n;k++)         {             c[i][j]+=a[i][k]*b[k][j];    ...

Electricity Bill

Electricity Bill program #include <stdio.h> void main() {     int units;     float charges;     char name[20];     printf("Enter the name of the customer\n");     scanf("%s",name);     printf("Enter the units consumed\n");     scanf("%d",&units);     charges=100;     if(units>0&&units<=200)     charges=charges+0.8*units;     else if (units>200&&units<=300)     charges=charges+0.8*200+(300-units)*0.9;     else     charges=charges+0.8*200+100*0.9+(units-300)*1;     if(charges>400)     charges=charges+0.15*charges;     printf("name=%s\n",name);     printf("units consumed=%d\n",units);     printf("charges=%f\n",charges); } Algorithm Start Read name, units consumed as units charge = 100 if units is <= 100 then  compute charge = charge + units * 0.8  el...

Simulation of a Simple Calculator | COMPUTER PROGRAMMING LABORATORY | 21CPL27/17

program #include<stdio.h> #include<stdlib.h> void main() {     float a,b,c;     char op;     printf("enter the two operands\n");     scanf("%f%f",&a,&b);     printf("enter an operator\n");     scanf("%f",&op);     switch (op) {     case'+': c=a+b;     printf("%f+%f=%f\n",a,b,c);     break;     case'-': c=a-b;     printf("%f-%f=%f\n",a,b,c);     break;     case'*': c=a*b;     printf("%f*%f=%f\n",a,b,c);     break;     case'/': if(b!=0) {     c=a/b;     printf("%f/%f=%f\n",a,b,c);     exit(0); }     else     printf("division by 0 error");     break;     default:     printf("enter valid operation"); } }  Algorithm Start  Read 2 numbers as a and b Read operator (+ or – or * or /) as op If op is + then display a ...