Friday, January 31, 2014

Calculated the size of the image when it is transmitted by Cable Modem

Am Image is 1024 x 768 pixels with 3 bytes/pixel. Assume the image is uncompressed. How long does it take to transmit it over a 56-kbps model channel? Over a 1-Mbps cable modem? Over a 10-Mbps Ethernet? Over the 100-Mbps Ethernet?

Size of the Image = 1024 x 768 x 3 bytes
          = 2359296 bytes
              = 18874368 bits

Division of two numbers using recursion implemented by C++

#include<iostream.h>
int div(int x,int y)
{
    if(x<y)
    return 0;
    else
    return(div(x-y,y)+1);
}

Sum of two numbers using recursion Implemented by C++

#include<iostream.h>
int sum(int x,int y)
{
    if(y==0)
    return x;
    else
   return(sum(x+1,y-1));
}

Product of two numbers using recursion Implemented by C++

#include<iostream.h>
int pro(int x,int y)
{
    if(y==0)
    return 0;
    else
    return(x+pro(x,y-1));
}

Thursday, January 30, 2014

Rotation in C Language


 

 
Point (X,Y) is to be rotated about the origin by angle theta to location (X',Y')
X' = X * cos(theta) - Y * sin(theta)
Y' = X * sin(theta) + Y *cos(theta)
or P' = R * P where  P' = [  X`,  Y' ],     P  = [X,Y]               
 
R  = |  cos(theta)   -sin(theta) |
     |  sin(theta)   cos(theta)  |
      
Rotation is performed about the origin (0,0) not about the center of the line/polygon/whatever



#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
    int gdriver=DETECT,gmode;

Reflection in c language

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
    int gdriver=DETECT,gmode;
    int midx=350,midy=300;
    int x1,y1,x2,y2;
    int x,y,i;

Small animation program in C Language

#include <graphics.h>
#include <conio.h>
#include <dos.h>
void main(){
int d,r;
int m;
int x;
int y;
d=DETECT;
initgraph(&d,&m,"c:\\tc\\bgi");

Bresenham circle drawing algorithm in c

#include<stdio.h>
#include <graphics.h>
#include <conio.h>
#include<math.h>
void main()
{
   int gdriver = DETECT, gmode;
   int p,x,y;
   int xc,yc,r;
   initgraph(&gdriver,&gmode,"c:/tc/bgi");

trapezoidal method

#include<iostream.h>
float y(float x)
{
    return(x/(1+x));
}

Runge kutta method

#include<iostream.h>
float f(float a,float b)
{
    float c;
    c=0.5*(1+a)*b*b;
   return c;
}

Newton's Forward formula

#include<iostream.h>
#include<conio.h>
#include<math.h>
double a[20][20];
int n;
void table()
{
    cout<<"\nEnter the number of terms=";
    cin>>n;
    cout<<"\nEnter First x's value=\n";

GAUSS-JORDAN-ELIMINATION-METHOD

                        /*GAUSS-JORDAN-ELIMINATION-METHOD*/
#include<iostream.h>
void main()
{
    float a[10][10],b[10][10],r;
    int i,j,k,n;
    cout<<"\nEnter the order of the matrix=";
    cin>>n;

Gauss elimination method

#include<iostream.h>
void main()
{
    float a[20][20],ratio,x[20];
    int i,j,k,n;
    cout<<"\nEnter the order of the matrix=";
    cin>>n;

Euler's Method

#include<iostream.h>
#include<math.h>
float f(float x,float y)
{
    return (pow(x,2)+pow(y,2));
}

bisection method (Numerical Problem)

#include<iostream.h>
#include<math.h>
float f(float x)
{
    return(exp(x)-3*x);
}

Hungarian Method

#include<stdio.h>
#include<conio.h>
void main()
{ int c[20][20],min,l,m,sr[20],sc[20],flag[20][20],i,j,k,rf[20],cf[20],n;
  int nrz[20],ncz[20],cn,a,noz,nrz1[20],ncz1[20];
  clrscr();
  printf("\nEnter the no of assignments:");
  scanf("%d",&n);

Dijkstra's algorithm

#include<stdio.h>
#include<stdlib.h>
void main()
{
    int graph[15][15],s[15],pathestimate[15],mark[15];
    int num_of_vertices,source,i,j,u,predecessor[15];
    int count=0;
    int minimum(int a[],int m[],int k);

Dual Simplex method

#include <stdio.h>
#include <conio.h>
#define INFINITY -999
#define N 10
#define M 20
/***************************************************/
/***** Solves the LPP by "DUAL SIMPLEX" method *****/
/***************************************************/
void minimum(float *arr,int *arrminpos,int n);
/* Calculates the minimum valued position among the array arr having n elements. */
void maximum(float *arr,int *arrminpos,int n);
/* Calculates the minimum valued position among the array arr having n elements. */
void display (float c[],float b[],float a[][M],int basic[]);

Solves the LPP by "SIMPLEX" method i.e. by table

#include <stdio.h>
#include <conio.h>
#define INFINITY 999
#define N 3
#define M 6
/************************************************************/
/***** Solves the LPP by "SIMPLEX" method i.e. by table *****/
/************************************************************/
void minimum(float *arr,int *arrminpos,int n);
/* Calculates the minimum valued position among the array arr having n elements. */
void display (float c[],float b[],float a[][M],int basic[]);

Wednesday, January 29, 2014

Permutation and Combination

#include<stdio.h>
#include<stdlib.h>
long fact(int n)
{
    if(n==0 || n==1)
    return 1;
    else
    return (n*fact(n-1));
}

Transpose Matrix

#include<stdio.h>
#include<conio.h>
void main()
{
    int a[2][3],b[3][2];
    int i,j,s=0,k;
    printf("\n Enter the elements of the  matrix=\n");

Symmetric Matrix

#include<stdio.h>
#include<conio.h>
void main()
{
    int a[3][3],b[3][3],n,m,n1,m1;
    int i,j,s=0,k;
    printf("Enter the order of the matrix=");
    scanf("%d%d",&m,&n);

Sparce Matrix

#include<stdio.h>
#include<conio.h>
void main()
{
    int a[3][3];
    int i,j,s=0,k;
    printf("\n Enter the elements of the  matrix=\n");

Matrix Addition and Multiplication with c language

#include<stdio.h>
#include<conio.h>
void main()
{
    int a[2][2],b[2][2],c[2][2],d[2][2];
    int i,j,s=0,k;
    printf("\n Enter the elements of the 1st matrix=\n");