CSE Rockz Home Blog Links Forum VSF

Monday, December 15, 2008

CHALLENGE 1:

Challenge is a special dimension 4 u guyz who want to challenge any one in c programming.....also for them who want to do more in 'c' but not satisfied with what u hav done yet .....

CHALLENGE 1:

1. /* write a program that accepts order of two matrices,accepts the values of respective elements,prints the respective matrices in matrix form like this:


a11 a12 a13 . . . . . . . . . .a1n
.
.
.
.
.
an1 an2. . . . . . . ann

and prints the sum of these matrices in the above form*/

2. /* write a program that accepts a number and prints following output
   











*/












3. /* write a flow chart which prints the following series...

1
12
123
1234
12345
.
.
.
.
.
.
.
123456789...............................n
12345.........................................n
12345.................................n-1
.
.
.
.
.
.
.
.
.
.
.
1
*/




*ppl intersted kindly mail the answers to cdscse@gmail.com the answers thus obtained will be posted in this blog*


BRAINY BYTES:1

Brainy Bytes are intersting facts or less known terminologies in computer feild:
these may not be quite a use for u but it pays just to know it.....

Brainy bytes 1: batch operating system - time sharing operating system :

In the second generation of computer development....a method called batch operating system was used. tn these systems,users had to prepare the data and the programs on a paper and then had to submit it manually to a computer centere for processing or compiling....the computer centere collected these user jobs and fed them into the computer in a batch wise at regular intervals,this batch wise output was then returned back to respective owners with result.

this caused a time delay between batches and users found it difficult to locate errors in thier program......and if they found they had to wait alot for reprocessing. .. . so, and John kemeny and Thomas kurtz of dartmouth collage introduced concept of time sharing- -operating system which allows a large number of users to use the main computer .there are many terminals connected to the main computer to use as feed.each terminal is used by a user providing acces to the main computer.this type of system is used in such a way that time of the main computer is divided into many slices and allocated one-by-one.the processing speed of the cpu is such that each user gets the illusion that he is using the computer alone.this introduction of time sharing helpd in productivity of programmers and also made online systems feasible,resulting in new applications like air line reaservation systems etc.

sources:

  • "Fundamentals Of Computing" by Pradeep.K.Sinha & Priti Sinha

Friday, December 12, 2008

BASICS:1

Topic 1:

Operators in c: 

operators are used to compose an expression out of two or more expressions to give a desired output.

operators in c are:

Arithmatic operators

the following operators are arithmatic operators

binariy arithmatic operators:

  • + - to add 2 numbers 
  • -  - to substract 2 numbers
  • *  - to multiply 2 numbers 
  • /  - to divide 2 numbers
  • % - to find reminder of 2 numbers
two numbers are required to perform these operations, hence we call these operators as binary operators

unary arthimatic operators:

  • ++  - increment operators
  • _ _ - decrement operator
  • -     - unary minus
  • size of() 
  • type casting

  • increment operator is used to increase the value in a certain variable by one.similarly decrement operators is used to decrease that value bye one
  • incrment operator or decrament operator is used before or after a variable,the value stored in operand changes but the order in which each operator in a sequence of operations is used differs from each operator.  
          
          eg.  when a=5;  
                  a++  +  a = 10;
                  
         eg. when a=5
                        ++a + a = 12;


  • so,in an post increment,incerment is done after all other operattions,where as in                 pre incerment, increment is done first and all other operations later

  • unary minus is an operator similar to binary minus but unary minus requires only a single operand

  • sizeof() operator is used to know the size of the operand stored in the particular variable.

eg.
if a is an short integer
size of(a); = 16

  • type casting is used to change the data type of a variable when required in an operation

  eg:  if a,b are integers
1.) c = a/b(float);

2.)c=a/b;

  • here in the above example...... operation 2 returns the type integer and operation 2 gives float...(float) is the type casting used here



Relational operators

  • the Relational operators in c are:

  • > - greater than 
  • < - lesser than
  • >= - greater than or equal to
  • <= - lesser than or equal to
  • == - equality operator
  • != - not equal to operator


  • the equality operator is used to check equivalance of two operands in a condition

  • the not equal to operator used to check inequality of two operands in a condition

  • all relational operators are binary

logical operators

  • && -is used when two conditions are to be checked and statements involving these conditions are to be executed if and only if both the conditions are true.
                               eg: a>b && b>c
  • || - is used when two conditions are to be checked and statements involving these conditions are to be executed if any one of  the conditions are true.
                            eg: b>a || b>c
  • ! - a negation operator is used when statements involving these conditions are to be executed if the negtion of the condition is true
                           eg:  a!=b;
  • all logical operators are binary


bitwise operators

  • bit wise operators are used to perform operations bit by bit within a variable.

  •  when this is used between two operands, the operands are written in binary format,and the operation is performed,every bit of resultant value is obtained by operating each and every bit of operands taken.
  

  • | - when this operator is used between two bits ,resultant is 1 if any one of the bits is 1           
                    eg: 0 1 0 1
                             0 1 0 1
                         
                 res   0 1 0 1


  • if & is used the resultant bit is 1 if and only if both the bits are 1

eg: 1 1 0 0
      0 1 1 0

             res    0 1 0 0

  • if ^ (xor-exclusive or) is used the result is 1 if and only if only one of the bits is 1

eg : 0 1 0 1
       1 0 0 1
      1 1 0 0

  • ~(negation) is used to convert any bit to its opposite bit (0~ = 1 ; 1~ =0)

  • left shift(>>) is used to shift a bit to its left and to fill current bit to zero
  • right shift (<<) is used shift a bit to its right and to fill current bit to zero


eg:

6<<4(shift 6 4 times)

0 0 0 0 0 1 1 0 0 - stge 1 -6
0 0 0 0 1 1 0 0 0 -stage 2- 12
0 0 0 1 1 0 0 0 0 - stage 3- 24
0 0 1 1 0 0 0 0 0- stage 4- 48 
  • left shift doubles the value and rigt shift reduces it by 2
  • all the bitwise operators are binary exept unary negation

conditinal operators

  • conditional operators are used to check a condition and assign a value to the operand based on the condition status
  • if condition is true,avalue is assigned , where as another value is assigned if it is false.

eg: a= (b>c)?b:c;

  • the above operation means that if b>c, b value is assigned to a,else c value is assigned

DAILY:1:FOR LOOP

 
date:12/12/08

Todays topic: Introduction to for loop.

For loop: 

Syntax:   for(intialization;condition;increment or decrement)

key points:

1. for loop comes under looping commands like while and do while.

2. in for loop all three operations are written at one place(intialization;condition;increment or  
decrement).unlike the while loop.

3. first time when a for loop is to be executed....it initializes first,then cheks the condition and proocedes...after executing it increments or decrements.the next time...i directly checks the given condition without any initialization....and after that it decrements or increments...the process continues untill c
ondition is satisfied..

4. scope of a for loop is only up to the next statment.to include more statements,bunch them with a couple of flower braces....
 


                 
                                                            A for loop flow chart



examples:

example1:

/* write a program to print 1 to 10 numbers using a for loop */

#include
main()
{
int i;

for(i=1;i<=10;i++)
{

printf("%d",i);

}

}

output:
12345678910


example2:

/*write a program which accepts a number and prints all numbers upto it*/


#include
main()
{

int n,i;
printf("enter a number");
scanf("%d",&n);

for(i=1;n=i;i++)
{


printf("%d",i);

}


}

output:
enter a number 5
12345

example 3:

/*write a program that accepts two numbers and prints all numbers between them*/

#include
main()
{

int n1,n2,i,s,b;
printf("give two numbers");
scanf("%d %d",&n1,&n2);

s=(n1>n2)?n2:n1;
b=(n2>n1)?n2:n1;

for(i=s;b>=i;i++)
{

printf("%d",i);

}

}

output:
give two numbers 3 7

34567


Nested for loop:

a for loop with in a for loop is called nested for loop.  



                                                        A nested loop flowchart


example:4;

/*write a program which prints 1 t0 10 5 times*/

#include
main()
{

int i,j;

for(i=1;i<=5;i++)
{

for(j=1;j<=10;j++)
{
printf("%d",i);
}
}




}


output:
1234567891012345678910..........



example:5:

*/write a program which prints an output
1
12
123
1234
12345
123456
1234567
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . n 

where n is input integer*/


#include
main()
{

int n,i,j;
printf("give n");
scanf("%d",&n);

for(i=1;n>=i;i++)
{

for(j=1;n>=j;j++)
{

printf("%d",j);
}
prinf("\n");
}



}


output: 

give n 6

1
12
123
1234
12345
123456


Welcome! CSE!!.....

hi....all this is a special blog 4 u ppl to run thru the key points and important facts of CDS sessions every week......this area gives scope 4 understanding all what is thought in the class.so,make use of this kind of dimension to guide urself in the next class.....