Sunday, November 21, 2010

CS201______2 Assignment Solution

#include<iostream.h>
void match(int [],int []);

main()
{
      int a,b,array1[10],array2[10];
      cout<<"Please enter 10 integers for array1:\n\n "<<endl;
      for(a=0;a<10;a++)
      {
              cout<<"Enter element "<<a+1<<": ";
              cin>>array1[a];
      }
      cout<<"\n\nPlease enter 10 integers for array2: \n\n"<<endl;
      for(b=0;b<10;b++)
      {
              cout<<"Enter element "<<b+1<<": ";
              cin>>array2[b];
      }
      match(array1,array2);
      system("pause");
      }


void match(int array1[],int array2[])
{
     int a,count=0,b;
     for(a=0;a<10;a++)
     {
             if(array1[a] == array2[a])
             {
                          count++;
             }
            
     }
     if(count ==10)
     {
              cout<<"\n\nBoth arrays are identical\n"<<endl;
     }
     else if(count == 0)
     {
              cout<<"\n\nThere is no matching element in both arrays\n"<<endl;
     }
     else    
     {
         cout<<"\nBoth arrays have same elements on\n"<<endl;
         for(b=0;b<10;b++)
         {
               if(array1[b] == array2[b])
               {
                          cout<<"Index "<<b+1<<endl;
               }
            
          }
     }  
          
}

Wednesday, November 10, 2010

Q.1

By using any division rule find voltage across 4kohm resistance.                               


Two resistances that are 2k ohm and 4k ohm are in series so we can add them as 6k ohm resistance.

Then we can calculate the current through the circuit by current division rule.

                                    I = R / Rt * It
                                    I = 6 / 18 * 2
                                    I = 0.67
This is the current that flowing through the 12k ohm resistance
Remaining current
                                    I4k = It – I 12k
                                                I4k = 2 – 0.67
                                    I = 1.33A

Current flowing through the 4k ohm resistance is 1.33 A so
                                    V= IR
                                    V = 1.33 * 4k
                                    V ~5320v




Q.2

Use nodal analysis to find IO in the network given below. Identify and label each node otherwise you will lose your marks. Write each step of the calculation to get maximum marks and also mention the units of each derived value







V2-V1=6
V2=6+V1

V1-10/4 + V1/2 + Ix = 0
V1-10+2V1+4Ix
3V1+4Ix=10----------------------------------------------------(1)


V2/10-5-Ix=0
V2-50-10Ix=0
V2-10Ix=50-----------------------------------------------------(2)


Adding these two equations
15V1+20Ix=50
2V2-20Ix=100

2V2+15V1=150

2(6+V1)+15V2=150
12+2V1+15V1=150
17V1=138
V1=8.12v
I=V/R
I=8.12/2
I=4.06A


Q.3
Use nodal analysis to write nodal equations for each node, except the reference node. Simplify the equations (final calculations not required).





At node 1 a

V1-20v/20+V1-V2/15+V1-10v/10=0

3V1-60v+4V1-4V2+6V1-60v=0
13V1=-120v-4V2=0


At node 2 b

V2-10v/5+V2-V1/15+V2-15v/35+25=0
12V2-120v+4V2-4V1+V2-15v=0
17V2-135v-4V1=0

At node 3 c
This is the reference node

At node 4 d

V4-10v/30+V4-V3/40=0
4V4-40v+3V4-3V3=0
7V4-40v+3V3=0