SUM THE FIRST 50 EVEN NATURAL NUMBERS

/*PROGRAM TO SUM THE FIRST 50 EVEN NATURAL NUMBERS*/
#include<stdio.h>
main()
{
int sum=0,i=2;
while(i<=100)
{
sum+i;
i+=2;
}
printf("Sum of first 50 even natural numbers=%d
",sum);

getch();
}

OUTPUT
Sum of first 50 natural numbers=2550


Read More..

How Bitwise Operators are Used an Example Program

Well, one-by-one we’ve discussed each of the Bitwise
Operator
. Starting from Operation
on Bits and Bitwise Operators
, we moved on to Right/Left
Bit Shift Operators
then discussed Decimal
Number to Binary Conversion Program
. and at last Ones
Complement and XOR Operators
. After having so much theoretical it’s
time now for a nice Example Program, which is the topic of today’s post.
The code here is basically to show how these bitwise operator are used rather
than what they are used for.



// Example Program to demonstrate how
// Ones Complement (~) and XOR (^)
// Opeartors are used.
#include<stdio.h>

// prototype
void showbits(short int);

// defined
void showbits(short int dec_num)
{
short int loop, bit, and_mask;

for(loop=15; loop>=0; loop--)
{
and_mask=1<<loop;
bit=dec_num&and_mask;


if(bit==0) printf("0");
else printf("1");
}
}

void main()
{
// declare three short ints
// for storing user inputs
// and results
short int a,b,res;
int ch;

while(ch!=7)
{
// show main menu
printf(" Main Menu
"
);
printf(" ---------
"
);
printf("1. Perform Left Bit Shift Operation
"
);
printf("2. Perform Right Bit Shift Operation
"
);
printf("3. Perform AND Operation
"
);
printf("4. Perform OR Operation
"
);
printf("5. Perform Ones Complement Operation
"
);
printf("6. Perform XOR Operation
"
);
printf("7. Quit
"
);
scanf("%d",&ch);

switch(ch)
{
case 1:
// take input
printf("

Enter a decimal number: "
);
scanf("%d",&a);
printf("
Enter number of places to shift bit: "
);
scanf("%d",&b);


printf("

Entered Number: "
);
showbits(a);
printf(" (decimal %d)",a);

// perform left bit shift
// operation
res=a<<b;

// show the formatted output
printf("
Left Shifted : "
);
showbits(res);
printf(" (decimal %d)

"
,res);

break;

case 2:
// take input
printf("

Enter a decimal number: "
);
scanf("%d",&a);
printf("
Enter number of places to shift bit: "
);
scanf("%d",&b);


printf("

Entered Number: "
);
showbits(a);
printf(" (decimal %d)",a);

// perform right bit shift
// operation
res=a>>b;

// show the formatted output
printf("
Right Shifted : "
);
showbits(res);
printf(" (decimal %d)

"
,res);

break;

case 3:
printf("

Enter two decimal number: "
);
scanf("%d",&a);
scanf("%d",&b);

printf("

Entered Number 1: "
);
showbits(a);
printf(" (decimal %d)",a);
printf("
Entered Number 2: "
);
showbits(b);
printf(" (decimal %d)",b);

// perform AND operation on two
// variables a and b
res=a&b;

printf("
ANDed : "
);
showbits(res);
printf(" (decimal %d)

"
,res);

break;

case 4:
printf("

Enter two decimal number: "
);
scanf("%d",&a);
scanf("%d",&b);

printf("

Entered Number 1: "
);
showbits(a);
printf(" (decimal %d)",a);
printf("
Entered Number 2: "
);
showbits(b);
printf(" (decimal %d)",b);

// perform OR operation on two
// variables a and b
res=a|b;

printf("
ORed : "
);
showbits(res);
printf(" (decimal %d)

"
,res);

break;

case 5:
// take input
printf("

Enter a decimal number: "
);
scanf("%d",&a);

printf("

Entered Number: "
);
showbits(a);
printf(" (decimal %d)",a);

// perform ones complement
// operation
res=~a;

// show the formatted output
printf("
~ed : "
);
showbits(res);
printf(" (decimal %d)

"
,res);

break;

case 6:
printf("

Enter two decimal number: "
);
scanf("%d",&a);
scanf("%d",&b);

printf("

Entered Number 1: "
);
showbits(a);
printf(" (decimal %d)",a);
printf("
Entered Number 2: "
);
showbits(b);
printf(" (decimal %d)",b);

// perform XOR operation on two
// variables a and b
res=a^b;

printf("
XORed : "
);
showbits(res);
printf(" (decimal %d)

"
,res);

break;

}
}
}


Test Run:


   Main Menu
---------
1. Perform Left Bit Shift Operation
2. Perform Right Bit Shift Operation
3. Perform AND Operation
4. Perform OR Operation
5. Perform Ones Complement Operation
6. Perform XOR Operation
7. Quit
1


Enter a decimal number: 3476
Enter number of places to shift bit: 3


Entered Number: 0000110110010100 (decimal 3476)
Left Shifted : 0110110010100000 (decimal 27808)

   Main Menu
---------
1. Perform Left Bit Shift Operation
2. Perform Right Bit Shift Operation
3. Perform AND Operation
4. Perform OR Operation
5. Perform Ones Complement Operation
6. Perform XOR Operation
7. Quit
2


Enter a decimal number: 543
Enter number of places to shift bit: 5


Entered Number: 0000001000011111 (decimal 543)
Right Shifted : 0000000000010000 (decimal 16)

   Main Menu
---------
1. Perform Left Bit Shift Operation
2. Perform Right Bit Shift Operation
3. Perform AND Operation
4. Perform OR Operation
5. Perform Ones Complement Operation
6. Perform XOR Operation
7. Quit
7
Press any key to continue...

Related Articles:


Read More..

Odd Loop

What is odd loop?
In real life programming, there are many times comes a situation when we dont know how many times the statements in the loop are to be executed.
There is comes concept of odd loop.
Execution of loop an unknown number of times can be done by - while, for and do...while loops.

/*A demonstration of odd loop using do...while*/
#include<stdio.h>
int main()
{
 int n;
 char answer;
 do
 {
  printf("Enter any number : ");
  scanf("%d", &n);
  printf("Square of %d is %d",n,n*n);
  fflush(stdin);
  printf("
Want to calculate more square y/n: "
);

  scanf("%c", &answer);
 }while(answer==y);
 return 0;
}

The output of above program would be:
Output of odd loop ( do..while) square C program
Figure: Screen shot of odd loop (do...while) to calculate
square of number C program 



The above odd loop program we can write using for loop as:

/*odd loop using for loop of calculate square number C program*/

#include<stdio.h>
int main()
{
 int n;
 char ans=y;
 for(; ans==y ; )
 {
  printf("Enter any number : ");
  scanf("%d", &n);
  printf("Square of %d is %d",n,n*n);
  fflush(stdin);
  printf("
Want to calculate more square y/n: "
);

  scanf("%c", &ans);
 }
 return 0;
}

The output of above program would be:
Output of odd loop ( for ) square C program
Figure: Screen shot of odd loop (for) to calculate 
square of number C program 



The odd loop program we can write using while loop as:
/*odd loop using while loop of calculate square number C program*/

#include<stdio.h>
int main()
{
 int n;
 char ans=y;
 while(ans==y)
 {
  printf("Enter any number : ");
  scanf("%d", &n);
  printf("Square of %d is %d",n,n*n);
  fflush(stdin);
  printf("
Want to calculate more square y/n: "
);

  scanf("%c", &ans);
 }
 return 0;
}



The output of above program would be:
Output of odd loop ( while ) square C program
Figure: Screen shot of odd loop ( while ) to calculate 
square of number C program 
Read More..

BASICs culture of diversity

One of the really interesting things about BASIC is that there are probably more dialects than any other programming language. Perhaps this is because BASIC really is the peoples language. Sure, there are different versions of C (a few), Cobol (why?), Forth, etc. but people just love to create their own version of BASIC for whatever reason.

I guess that since BASIC was born into a world where it was shoehorned into many, many different computers it became part of the BASIC culture that it is okay to have many broadly different implementations. Every early home computer had its own BASIC.

Now Ive heard it said that this is a weakness of BASIC, and many people complain that there is no commercially viable standard BASIC. Im not sure why this is a problem. The standard (by committee) is very old and limited. Since the world is constantly changing, I think its a good thing that BASIC hasnt settled down into a rut. BASIC is still a place where people feel free to explore and innovate.

The world is big enough to accomodate variety.
Read More..

Number Rectangle Pattern

Q. Write a C program to print the following number pattern rectangle as:

1 2 3 4 5 4 5
2 3 4 5 3 4 5
3 4 5 2 3 4 5
4 5 1 2 3 4 5

Ans.

/*c program for number pattern rectangle design*/
#include<stdio.h>
int main()
{

 int n=4,num=5,p=4,r,c,z;
 for(r=1; r<=n; r++,p--)
 {
   for(c=r; c<=num; c++)
      printf(" %d",c);
   for(c=1,z=p; c<=r+1; c++,z++)
     printf(" %d",z);
   printf("
"
);

 }
 getch();
 return 0;
}

/***********************************************************
The output of above program would be:
************************************************************/


Output of Number Rectangle Pattern C program
Figure: Screen-shot for Number Rectangle Pattern C program

Read More..

Instinct

Instinct is a Resident Evil rip-off with a first-person perspective thats a good 10 years too late for the party. This creation of the aptly named Russian developer Digital Spray Studios has more problems than just copying the story and bad guys from a game with a best-before date that expired in the 1990s. Everything here is ineptly made and annoying, from the dumb zombie foes to the terrible level design. Throw in big performance problems that regularly turn battles into slideshows and youve got yet another atrocity good for a trifecta of crap.

The storyline appears to be a garden-variety zombie caper, with you guiding three Russian commandos on a search-and-destroy mission to a secret facility in North Korea. You start off facing run-of-the-mill soldiers, but immediately run into what looks to be the undead as soon as you enter the base. Or so it seems. The plot continually bounces back and forth in time, with cutscenes filling in the backstory only after youve completed missions. While this style of storytelling might work well in the hands of a competent storyteller, its just confusing here. You start off watching a clip of a drunken Russian soldier taking out a TV a la Elvis and then plunge right into the invasion of some kind of military base. If not for the blurbs on the box cover and in the manual, you wouldnt have a clue whats going on until wrapping up at least three levels.




Another big problem is the developers decision to leave all of the dialogue in the original Russian. While its sweet of Digital Spray to save us from what would no doubt have been mangled English dubbed by family and friends of the development team, not being able to understand anything said by your comrades in the middle of firefights isnt a great alternative. Bringing up a separate journal screen with subtitled dialogue is the only way to figure out what your pals are saying, and this is tantamount to suicide since the action continues in the background while youre trying to read. By the time youve gotten an idea of what youre supposed to be doing, the zombies on your heels will usually have caught up to you and started busily pounding on your skull. Not fun.

But this handicap is one of the few things that makes combat in Instinct remotely challenging. Enemy soldiers are total morons who frequently take cover behind explosive barrels. These barrels can typically be found adjacent to all soldiers, so its a lot easier to just target them whenever spotted and then rely on the ensuing ka-boom to take out any bad guys in the neighborhood. Shooting soldiers directly isnt nearly as effective or as satisfying, as they absorb a ridiculous number of rounds before eating the pavement and show absolutely no signs of being shot even while youre riddling them with bullets. Not surprisingly, the zombies are pretty stupid, too, although at least they have the excuse of being the victims of a mind-destroying experiment gone horribly wrong. Regardless, they pretty much line up to be gunned down. They pose a threat only when they attack in large numbers, and even then you can still blast them to bits without much of a hassle as long as youve got a little room to fall back whenever you need to reload a weapon.

More difficulty is provided by the level design, although thats largely because of the typically terrible layout. Most of the rooms and corridors all look the same, making it easy to get turned around. Getting lost is an impossibility due to the small size of the levels, at least, although youll sure get bored looking at the same grey metal walls, gas tanks, and explosive barrels over and over again. Its also hard to figure out what youre supposed to do in spots. Levers are never highlighted, so you can readily miss a switch that needs to be pulled to open a door. Sometimes zombie attacks are only triggered by entering a certain part of a level. You can wander around for ages looking for a door that doesnt exist only to eventually get attacked out of nowhere by finally walking into the right place.

Visuals are noteworthy solely for what have to be the least scary zombies in gaming history. Many of them are clad in tracksuits, so at times it seems like youre being attacked by packs of old-school rappers. Few details have been incorporated in the zombie models, either. Their bodies are blurry and their faces are pale blobs distinguished by rolled-up eyes and bulging veins only visible in extreme close-ups. Digital Spray has tried to give the game something of a unique look through a comic-book display mode, although all this does is outline everything with thin white lines that obscure much of the scenery. Both the regular and comic-book graphics have serious performance issues, as well. The frame rate tends to plummet when a fair number of enemies are onscreen, particularly in wide-open settings. And little hitches and flat-out long freezes are common when simply turning around during battles.




But at least bits of the audio can be effective, particularly the music. Even though the score lapses into dreary, driving techno typical of yesterdays shooters when in the middle of firefights, the atmospheric music played when creeping around in the dark on zombie levels is truly spine-tingling. Toss in some squelching footfalls when you walk through gore, the satisfying boom of your shotgun, and the efficient rat-a-tat-tat of your automatic weapons and youve got a pretty decent-sounding shooter.

Still, the many flaws in Instinct outweigh a few creepy tunes and shotgun blasts. All of the above details should be more than enough to scare you off, but if you need further evidence, please take note that saves take really long to load, there are no multiplayer modes, and that the game is copy-protected by Starforce.



By Brett Todd, GameSpot
Read More..

WaterField Muzetto Laptop Bag Review

by Allison Johnson

If you think the way I do, youll agree that its easier to drop a few hundred bucks on a bag you can write off as an "investment piece." That seems to be the idea here - quality materials, good structure, and classic style that will stand up to several years of use.

WaterField Muzetto Laptop Bag Specifications:

  • Notebook Compatibility: Up to 13 inch notebook
  • Bag Dimensions: 14 x 11 x 2.5 inches
  • Construction: Leather exterior, metal hardware, nylon textile interior
  • Weight: 1.7 lb.
  • Price: $239.00 at www.sfbags.com

WaterField Muzetto Laptop Bag

WaterField is a San Francisco-based operation, turning out high-end bags and cases for laptops, iPhones and beyond. Their style is urban-meets-professional with an emphasis on higher quality materials. Of course, this all comes at a premium. The Muzetto laptop bag sports a hefty $239 price tag. Is the extra style and quality worth all of that extra cash? This is the question that weighed on my mind as I spent some time with the Muzetto bag slung over my shoulder.

Build and Design
The Muzetto is a messenger-style bag. Its vertically oriented, snug against the hip and takes up relatively little space. The large laptop compartment and a thin pocket on the back are lined in a bright orange material, making it easy to find objects buried deep inside the bag.

WaterField Muzetto Laptop Bag WaterField Muzetto Laptop Bag

The leather on the bags exterior is treated with oil before it reaches the consumer, so it should be weather-resistant. Metal d-rings connect the woven nylon strap to the body of the Muzetto, and a removable Velcro pad keeps it comfortable against the shoulder.

WaterField Muzetto Laptop Bag

Under the large, weighted flap youll find the main laptop compartment ready for a 13 inch notebook, a slightly smaller pocket and another shallow pocket for portable devices. WaterField keeps it simple, skipping the small pockets for pens and business cards that youll find on most business laptop bags. Unlike the large compartment, the pockets are lined in a darker textile, making it just a bit more difficult to find that tiny USB key you dropped into the bottom of the bag.

WaterField Muzetto Laptop Bag

One thing this bag lacks is substantial padding in the laptop compartment. The bag itself is sturdy, no doubt, but without an extra layer to cushion your notebook from the bumps of everyday use, youll want to invest in a sleeve as well.

WaterField Muzetto Laptop Bag WaterField Muzetto Laptop Bag

Performance
The Muzetto performs just as well as it looks. The hardware is sturdy and the shoulder strap is comfortable. Did we mention that it looks good? It does. It looks very good.

While taking the bag out for a spin, I was caught in a couple of light rain showers. Based on my experience, I can agree with WaterField and say that the Muzetto will stand up to a little bit of foul weather.

Its a slim messenger bag, but I found enough pockets and storage space for my Dell Latitude E6400, an Asus Eee PC 1008HA Seashell netbook, a slim point-and-shoot, and a few other small items. This filled the bag to capacity. You wont be able to fit too many bulky items into the Muzetto, but its spacious enough for a notebook and a couple of lifes necessities. For anything more, youll need to find a bigger bag.

WaterField Muzetto Laptop Bag

Conclusion
Ill just spell it out - I like this bag. Let me count the ways: premium materials, simple design, and comfortable to use. If it were up to me, it would pack a few small pockets for the hodge-podge of pens, gadgets and nonsense that I tend to carry with me everywhere. It would also cost about a hundred dollars less. Aside from that, the WaterField Muzetto is a very fine bag.

Pros:

  • Very attractive design
  • High-quality leather exterior
  • Gold lining in main compartments

Cons:

  • No small pockets for phone, iPod and other gadgets
  • Relatively high cost
  • Little padding in laptop compartment
Related links :
Read More..

Blog Archive

Powered by Blogger.