Earn by twitter on twivert

Sign up for PayPal and start accepting credit card payments instantly.

Sunday, September 19, 2010

WAP that look-alike of the function strcopy( )


/*WAP that look-alike of the function strcopy( ) */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  source[ ] = "codezworld" ;
 char  target[20] ;

 xstrcpy ( target, source ) ;
 printf ( "\nsource string = %s", source ) ;
 printf ( "\ntarget string = %s", target ) ;
}

xstrcpy ( char  *t, char  *s )
{
 while ( *s != '\0' )
 {
  *t = *s ;
  s++ ;
  t++ ;
 }
 *t = '\0' ;
}

WAP to Use of string copy strcopy() function


/*WAP to Use of string copy strcopy() function */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  source[ ] = "codezworld" ;
 char  target[20] ;

 strcpy ( target, source ) ;
 printf ( "\nsource string = %s", source ) ;
 printf ( "\ntarget string = %s", target ) ;
}

WAP that look-alike of the function strlen( )


/*WAP that look-alike of the function strlen( ) */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  arr[ ] = "codezworld" ;
 int  len1, len2 ;

 len1 = xstrlen ( arr ) ;
 len2 = xstrlen ( "A blog of programs" ) ;

 printf ( "\nstring = %s length = %d", arr, len1 ) ;
 printf ( "\nstring = %s length = %d", "A blog of programs", len2 ) ;
}

xstrlen ( char  *s )
{
 int  length = 0 ;

 while ( *s != '\0' )
 {
  length++ ;
  s++ ;
 }

 return ( length ) ;
} 

WAP to find length of string using strlen() function


/*WAP to find length of string using strlen() function */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  arr[ ] = "codezworld" ;
 int  len1, len2 ;

 len1 = strlen ( arr ) ;
 len2 = strlen ( "A blog of programs" ) ;

 printf ( "\nstring = %s length = %d", arr, len1 ) ;
 printf ( "\nstring = %s length = %d", "A blog of programs", len2 ) ;
}

WAP to Input of strings containing spaces


/*WAP to Input of strings containing spaces */
#include<stdio.h>
#include<conio.h>
main( ) 
{
 char  name[25] ;

 printf ( "Enter your full name " ) ;
 gets ( name ) ;
 puts ( "Hello!" ) ;
 puts ( name ) ;
}

WAP to input & print a string


/*WAP to input & print a string */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  name[25] ;
 printf ( "Enter your name " ) ;
 scanf ( "%s", name ) ;
 printf ( "Hello %s!", name ) ;
}

WAP to Unsigned shifting a byte value


/*WAP to Unsigned shifting a byte value.
Save As: ByteUShift.java
*/
class ByteUShift {
static public void main(String args[]) {
char hex[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
byte b = (byte) 0xf1;
byte c = (byte) (b >> 4);
byte d = (byte) (b >>> 4);
byte e = (byte) ((b & 0xff) >> 4);
System.out.println(" b = 0x" + hex[(b >> 4) & 0x0f] + hex[b & 0x0f]);
System.out.println(" b >> 4 = 0x" + hex[(c >> 4) & 0x0f] + hex[c & 0x0f]);
System.out.println(" b >>> 4 = 0x" + hex[(d >> 4) & 0x0f] + hex[d & 0x0f]);
System.out.println("(b & 0xff) >> 4 = 0x" + hex[(e >> 4) & 0x0f] + hex[e & 0x0f]);
}
}

WAP to Masking sign extension


/*WAP to Masking sign extension.
Save As : HexByte.java
*/
class HexByte {
static public void main(String args[]) {
char hex[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
byte b = (byte) 0xf1;
System.out.println("b = 0x" + hex[(b >> 4) & 0x0f] + hex[b &
0x0f]);
}
}

WAP to Left shifting as a quick way to multiply by 2


/*WAP to Left shifting as a quick way to multiply by 2.
Save As: MultByTwo.java
*/
class MultByTwo {
public static void main(String args[]) {
int i;
int num = 0xFFFFFFE;
for(i=0; i<4; i++) {
num = num << 1;
System.out.println(num);
}
}
}

WAP to Left shifting a byte value


/*WAP to Left shifting a byte value.
Save As ByteShift.java
*/
class ByteShift {
public static void main(String args[]) {
byte a = 64, b;
int i;
i = a << 2;
b = (byte) (a << 2);
System.out.println("Original value of a: " + a);
System.out.println("i and b: " + i + " " + b);
}
}

WAP to Demonstrate the bitwise logical operators


/*WAP to Demonstrate the bitwise logical operators
Save As: BitLogic.java
*/
class BitLogic {
public static void main(String args[]) {
String binary[] = {
"0000", "0001", "0010", "0011", "0100", "0101", "0110",
"0111",
"1000", "1001", "1010", "1011", "1100", "1101", "1110",
"1111"
};
int a = 3; // 0 + 2 + 1 or 0011 in binary
int b = 6; // 4 + 2 + 0 or 0110 in binary
int c = a | b;
int d = a & b;
int e = a ^ b;
int f = (~a & b) | (a & ~b);
int g = ~a & 0x0f;
System.out.println(" a = " + binary[a]);
System.out.println(" b = " + binary[b]);
System.out.println(" a|b = " + binary[c]);
System.out.println(" a&b = " + binary[d]);
System.out.println(" a^b = " + binary[e]);
System.out.println("~a&b|a&~b = " + binary[f]);
System.out.println(" ~a = " + binary[g]);
}
}

WAp to Demonstrate ++ operator


/*WAp to Demonstrate ++ operator
Save as: IncDec.java
*/
class IncDec {
public static void main(String args[]) {
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
System.out.println("d = " + d);
}
}

WAP to Demonstrate several assignment operators


/*WAP to Demonstrate several assignment operators*/
class OpEquals {
public static void main(String args[]) {
int a = 1;
int b = 2;
int c = 3;
a += 5;
b *= 4;
c += a * b;
c %= 6;
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
}
}

WAP to Demonstrate the % operator


/*WAP to Demonstrate the % operator*/
class Modulus {
public static void main(String args[]) {
int x = 42;
double y = 42.3;
System.out.println("x mod 10 = " + x % 10);
System.out.println("y mod 10 = " + y % 10);
}
}

ADS

How to earn online

How to earn online:
Step - 1 :
signup for PayPal, to recieve your online earning
click here:
https://www.paypal.com/in/mrb/pal=CZ7224TZBMCBL
step - 2 : Singup these 4 sites & earn & enjoy! Read site to know how to earn.
1. trekpay
Earn up to $0.02 (2 cents) per click.
http://www.trekpay.com/?ref=34690
2. neobux
Earn up to $0.02 (2 cents) per click.
Click here:
http://www.neobux.com/?r=Moneyearner786

AddMe

Bookmark and Share