Earn by twitter on twivert

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

Wednesday, December 29, 2010

LIKE command


LIKE command

select stdName,stdAddress
from student
where stdName like 'ABC'

Sunday, December 26, 2010

Give yourself more screen real estate in Windows 7’s


Give yourself more screen real estate in Windows 7’s.
These tips apply primarily to Windows 7

You can shrink Windows 7’s oversize taskbar icons by right-clicking the taskbar, 
choosing Properties, and selecting Use small icons. This option shrinks the size of the taskbar by half, giving you a few extra millimeters of vertical screen space.

Tuesday, December 14, 2010

WAP to use while loop in PL/SQL


WAP to use while loop in PL/SQL
step-1

RUN THIS COMMAND

create table tb1(id number);
  
IF SUCCESSFULLY RUN THEN WRITE PL/SQL COMMAND
step-2

declare
vid number:=0;
begin
while(vid<=10)
loop
insert into tb1(id)
values(vid);
vid:=vid+1;
dbms_output.put_line(vid);
end loop;
end;

Tuesday, December 7, 2010

WAP to use for-loop in PL/SQL


WAP to use for-loop in PL/SQL
step-1

create table tb1(id number);
  
RUN THIS COMMAND, IF SUCCESSFULLY RUN THEN WRITE PL/SQL COMMAND
step-2

declare
vid number:=0;
begin
for vid in 1..10
loop
insert into tb1(id)
values(vid);

dbms_output.put_line(vid);
end loop;
end;

Monday, December 6, 2010

Lowercase all-capitals text in a trice


Lowercase all-capitals text in a trice.
These tips apply primarily to Windows 7

In Microsoft Office apps, convert the text to lowercase by 
selecting it and pressing shift + f3.
Press  a second time to convert the text to title case. 
 

Saturday, December 4, 2010

WAP to use cursor in pl/sql


WAP to use cursor in pl/sql
step-1 create a table

create table student(stdRollNo number, stdName varchar2(25), 
stdClass varchar2(25));
  
RUN these COMMAND IF SUCCESSFULLY RUN THEN WRITE
step-2 insert 2 or more values

insert into student
values(01,'ABC','XII');
  
RUN these COMMANDs, IF SUCCESSFULLY RUN THEN WRITE PL/SQL COMMAND
step-3
  
declare
vid number;
vname varchar2(25);
cursor std is
select stdRollno,stdName 
from
student
where stdClass='XII';

begin
open std;
loop
fetch std into vid,vname;
exit when std%notfound;
dbms_output.put_line(vid);
end loop;
close std;
end;

Monday, November 29, 2010

WAP to use for-reverse loop in PL/SQL


WAP to use for-reverse loop in PL/SQL
step-1
create table tb1(id number);
  
RUN THIS COMMAND, IF SUCCESSFULLY RUN THEN WRITE PL/SQL COMMAND
step-2

declare
vid number:=0;
begin
for vid in reverse 1..10
loop
insert into tb1(id)
values(vid);

dbms_output.put_line(vid);
end loop;
end;

Saturday, November 27, 2010

WAP to use procedure in pl/sql


WAP to use procedure in pl/sql
step-1 create a table

create table student(stdRollNo number, stdName varchar2(25)
, stdClass varchar2(25));
  
RUN these COMMANDs, IF SUCCESSFULLY RUN THEN WRITE PL/SQL COMMAND
step-2
 
create or replace procedure
print(vid number,vname varchar2(25))
is
begin
insert into student(stdRollno,stdName)
values(vid,vname);
end print; 
 
RUN these COMMANDs, IF SUCCESSFULLY RUN THEN WRITE following 
COMMAND
step-3
 
begin
print(01,'xyz');
end print; 
 
 

OR command


OR command
select stdName 
from student
where stdRollno=2 or stdRollno=3

Thursday, November 25, 2010

Customize your system tray


Customize your system tray.
These tips apply primarily to Windows 7

Windows 7 helpfully decreases the amount of space dedicated to 
the Notification Area by putting all but the most essential 
notifications within a drop-down (or, in this case, drop-up) 
box. It looks nice, but you can burn lots of time with wasted 
clicks as you hunt for what you need. If you want regular, 
click-free access to some of these notifications, change the 
default layout. It’s easy to do. Just open the tray’s spillover 
window and drag the icons you want to the taskbar area. You can 
rearrange icons within the added window, too. 
 

Wednesday, November 24, 2010

Wednesday, November 17, 2010

WAP to use loop in PL/SQL


WAP to use loop in PL/SQL
step-1
create table tb1(id number);
 
RUN THIS COMMAND, IF SUCCESSFULLY RUN THEN WRITE PL/SQL COMMAND
step-2
 
declare
vid number:=0;
begin
loop
vid:=vid+1;
insert into tb1(id)
values(vid);
if(vid>=10) then
exit;
end if;
dbms_output.put_line(vid);
end loop;
end;

Snap windows faster


Snap windows faster.
These tips apply primarily to Windows 7
Source: PC World

But what if you like Aero Snap? Here is a faster way to snap 
windows right or left by using keyboard shortcuts instead of 
the mouse.  snaps left, and  snaps right. While we’re at it,  
will maximize your window, while  will minimize it. 
(Note, however, that if you have done the Registry hack 
described in the preceding tip to turn off Aero Snap, that 
hack will have disabled these particular shortcuts, too.)

Monday, November 15, 2010

Get a quick peek at the desktop


Get a quick peek at the desktop.
These tips apply primarily to Windows 7

Simply click  to hide all open windows. Keep the  held down and 
then release that key to return to your former environment with 
all its open windows in place.

Sunday, November 14, 2010

WAP to search a character in a string


/*WAP to search a character in a string*/
#include<stdio.h>
#include<conio.h>
#include<string.h>

main()
{
 char *ptr, str[50];
 int ch;
 // Input of String & character
 printf("\n Enter the String \n");
 gets(str);
 printf("\n Enter the character to search ");
 ch = getchar();
 // Searching the character
 ptr = strchr(str,ch);
 if(ptr == NULL)
  printf("\n Not Found");
 else
  printf("\n The character %c is at the position %d\n",ch,ptr-str);
 getch();
 return 0;
}

bc command for calculation in linux


bc command for calculation in linux
cmd---------


$bc

e.g---------
$bc
2+5
7 //output

Saturday, November 13, 2010

Make Internet Explorer load faster


Make Internet Explorer load faster.
These tips apply primarily to Windows 7
Source: PC World

When IE loads very slowly for no clear reason, it’s usually 
due to an add-on 
clogging the pipes. Fortunately, one of IE’s best features is that it allows you to
see how long each add-on is taking to load. You can find this under Tools Manage
Add-ons. Check the ‘Load time’ column to see what has been weighing you down.

Zoom faster in Windows 7 and Vista


Zoom faster in Windows 7 and Vista
These tips apply primarily to Windows 7

Source : PC World
In Windows 7 and Vista,  lets you zoom in and out in most 
applications. In Windows Explorer, this combo makes icons 
and thumbnails larger or smaller. In Web browsers and most 
graphics programs, it changes the font size or the zoom 
level up and down. 
 

Control your post-vacation time


Control your post-vacation time.
These tips apply primarily to Windows 7
Source : PC World

Never schedule anything for the day after you come back from a 
long trip or vacation, since you’ll need this day to catch up 
on everything you’ve missed while you were out. If you use a 
shared calendar system, book the entire day of your return with 
“meetings” before you leave. 

Friday, November 12, 2010

Fix a Computer Clock That Forgets the Time


Fix a Computer Clock That Forgets the Time


A computer can fail to keep good time for a number of reasons.
It could be the result of Windows failing to connect to its timesync
server, or it could be due to a dead CMOS battery.
Readjusting the clock fixes the problem
for his current session, but every time he reboots, the clock
automatically readjusts itself based on the time-zone setting.
Fortunately, this is a super-easy problem to fix:

1. Right-click the clock in the System Tray (bottom-right corner)
and click Adjust date/time. 



 
2. In the ‘Date and Time’ tab of the resulting dialog box, click
Change time zone. Choose the proper time zone for your location.

3. Click OK, then click OK again. Done! Done! Done!

Change Your Windows User-Account Picture


Change Your Windows User-Account Picture



When you click the Start menu (or visit the Windows log-on screen),
you see an arbitrary thumbnail image of a fl ower, a soccer ball, a
rubber ducky, or one of a handful of other stock Windows images.
Though you don’t get many choices when you initially set up your
PC (and in some cases you don’t get a choice at all), you can easily
change the image that’s assigned to your user account. Here’s how
(in Windows 7; the procedure may vary slightly in earlier versions):

1. Open the Control Panel and choose User Accounts. (Windows
Vista and 7 users can follow an alternative route to User Accounts
if they like: Click Start, type User Accounts, and press .) 
 
2. Click Change your picture.
3. If you don’t want any of the available thumbnails, click
Browse for more pictures.
4. Navigate to the desired folder and choose the BMP, GIF, JPEG,
or PNG image you want. 

 
for windows XP
1. Click Start --> click on Control Panel.
2. click on user Account in control panel window.
3. click on administration from "pick an account to change".
4. choose change my picture.
5. choose picture or browse.
6. click on change picture button.

Thursday, November 11, 2010

Save time with VoIP


Save time with VoIP.
These tips apply primarily to Windows 7

Source: PC World

You can save significant time—and possibly money, too—by using a 
VoIP system that allows you to click phone numbers in Web pages 
and in e-mail messages and dial them directly via your PC. 
Skype (skype.com) offers such an option, which works broadly in 
e-mail and on most Websites, and Google recently integrated its 
own VoIP offering, Google Voice, into Gmail (gmail.com). 
In addition, Google Voice saves call histories as they take place, 
integrating them into the Gmail contact management system. 

Tuesday, November 9, 2010

Pin almost anything to the taskbar


Pin almost anything to the taskbar.
These tips apply primarily to Windows 7

Source: PC World
 
There is practically no limit to the things you can pin to the 
task-bar: 
often-used folders, the Control Panel, even a button to shut 
down your PC. (For the last option, find shutdown.exe in the 
System/Windows32 directory, create a shortcut to it, and then 
append this text to the target in Properties: /s /f /t 00).

Sunday, November 7, 2010

Alter Windows Explorer’s ‘Favorites’


Alter Windows Explorer’s ‘Favorites’.
These tips apply primarily to Windows 7

Source: PC World
 
Drag folders to the top left of the screen from within Explorer 
and then organize them however you like. Right-click and select 
remove to get rid of anything you don’t want. 
 

PL/SQL command


PL/SQL
step-1 create a table

create table student(stdRollNo number, stdName varchar2(25), 
stdClass varchar2(25));
  
RUN THIS COMMAND, IF SUCCESSFULLY RUN THEN WRITE PL/SQL COMMAND

step-2 
 

declare
vid number:=1;
vname varchar2(25):='xyz';
vclass varchar2(25):='X';
begin
insert into student(stdRollNo, stdName , stdClass)
values(vid,vname,vclass);
end;

Liberally use Windows 7’s Jump Lists


Liberally use Windows 7’s Jump Lists.
These tips apply primarily to Windows 7

Source: PC World
 
You can access the Jump Lists by right clicking on any icon 
in the taskbar. You’ll find recently used documents, along 
with certain app-specific functions (such as setting your 
IM client to ‘Away’). One little time-saver: You can pin a 
Web URL to your browser’s Jump List by dragging that URL to 
the browser icon in the taskbar (do this by clicking on the 
mini icon in the URL bar).

Default to the Documents Library


Default to the Documents Library.
These tips apply primarily to Windows 7

Source: PC World
 
In Windows 7, when you launch Windows Explorer, the view automatically 
defaults to the Libraries Folder, which for many users is not very 
useful. Busy types will typically drill straight to the Documents 
Library from there. Save a click by instructing Explorer to default to 
the Documents Library. To do this, right-click on the Windows Explorer 
shortcut (the taskbar shortcut won’t work). In the Target field, type or 
paste: %windir%\explorer.exe ::{450D8FbAAD25-11D0-98A8-0800361b1103} 
Finally, replace the icon in the taskbar with your tweaked shortcut.

Power up the ‘Send To’ feature


Power up the ‘Send To’ feature.
These tips apply primarily to Windows 7

Source: PC World
 
When right-clicking a file in Windows Explorer, hold down  before 
you click and then select the Send To command. Windows will reveal 
a whole host of additional options, such as one to move the file to 
an often-used folder.

Use Outlook’s categorization system.


Use Outlook’s categorization system.
These tips apply primarily to Windows 7

Source: PC World
 
Outlook lets you color-code messages, task-list items, calendar 
entries, and even contacts into as many as six categories. 
Figure out a system and stick to it: red for business, for 
example, and blue for personal items. Or color-code items by 
level of urgency: green for “must do today,” blue for “to do 
this week,” and yellow for “to do this month.” 

Select multiple files easily


Select multiple files easily.
These tips apply primarily to Windows 7

Source: PC World
 
Using the or  keys to select multiple files in Windows Explorer 
can be difficult and an invitation to commit errors. If, however,
you frequently need to open or manipulate multiple files at once,
turn on Windows’ Check-box system—it lets you select files more 
easily. In Windows Explorer, you can find this setting under or 
ganize Folder and search options View. Scroll down and select Use
check boxes to select items; then click OK.

Make important e-mail more findable.


Make important e-mail more findable.
These tips apply primarily to Windows 7

Source: PC World
 
Just change the subject lines. Few things are more annoying than 
receiving an important e-mail message that carries a clueless 
subject like “hey” (or worse, an empty subject line). A more 
meaningful subject line improves your search index 
and makes your e-mail thread more valuable in general. In Outlook, 
open the message(this tactic doesn’t work with just a preview), 
select the subject line, and type over it with the more-useful text
you want.

Don’t constantly check your e-mail


Don’t constantly check your e-mail.
These tips apply primarily to Windows 7

Source: PC World
 
Frequent checking breaks your concentration and interrupts what 
you’re doing, wasting time as you return your focus to the task 
at hand. Reduce how often your e-mail client checks for new 
messages to something less distracting: Every 10 or 15 minutes 
should give you time enough to focus without keeping people 
waiting overly long for a response. In Outlook, click S and tweak 
the digits for ‘Schedule an automatic send/receive every minutes’.

Drag in Outlook


Drag in Outlook.
These tips apply primarily to Windows 7

Source: PC World
 
In Outlook, you can drag any item to any other area of the 
program, and it will create a new item there, with the dragged 
information as part of the new item or event. Drag an e-mail 
to the Contacts button, and it will create a new contact for 
the sender, automatically populating the Name and E-mail fields, 
and putting the body of the message in the Notes field. Drag a 
contact to the Calendar, and you’ll create a Meeting Invitation 
ready to be sent to that person, and so on.

Rename files fast


Rename files fast.
These tips apply primarily to Windows 7

Source: PC World
 
Renaming lots of files in Windows Explorer? Select the first 
file in your list, press , and type the new name. When finished,
press  instead of . Explorer will jump you to the next file in 
the list and automatically select the entire file name so you can 
rename it without having to press the  key. Continue pressing 
and you’ll zip through the list one file at a time. 

Improve Windows Search.


Improve Windows Search.
These tips apply primarily to Windows 7

Source: PC World
 
If Windows Search isn’t finding everything that you know you’ve 
saved, check the Windows Indexing Options (type indexing options
into the Windows 7 Start Menu search bar), and then check the 
locations that are included in the search index. Click Modify, 
and navigate through the C: drive to add more locations to index. 

Customize your browser’s default search engine.


Customize your browser’s default search engine.
These tips apply primarily to Windows 7

Source: PC World
 
Your PC builder has likely preset Internet Explorer’s default 
search engine to the one that’s paying it the most. Otherwise, 
it’ll be set to Microsoft’s liking: Bing. Change this setting 
by clicking the drop-down arrow in the top right corner of the 
IE window (within the search box), and click Find More Providers. 
You won’t find Google without a hunt, so type Google into the 
‘Find add-ons…’ search box, and select the first result, Google 
Search Suggestions. Click Add to Internet Explorer, and at the 
pop-up, click Make this my default search provider. 

Delete command


Delete command
delete student
where stdAddress='kota'

select command


select command
stdName, stdAddress is field
table student
----------CODE--------------
select stdName 
from student
where stdAddress='kota'

Saturday, November 6, 2010

remove a table in SQL


remove a table in SQL
--------CODE---------

drop table student

modify one or more records in specified relation in SQL


modify one or more records in specified relation in SQL
here stdAddress and stdRollno is field name
----------------------CODE----------------------------
update student
set stdAddress='kota'
where stdRollno='1'

insert domain at specified field in SQL


insert domain at specified field in SQL
here stdAddress is field name
and goa is value it.
--------------CODE---------------------

insert into student(stdAddress)
values('goa');

Friday, November 5, 2010

Minimize all windows in windows 7


Please note: These tips apply primarily to Windows 7

Minimize all windows (except the one that you’re working on).   When your desktop becomes so cluttered that you can’t find anything, this step is a good way to regain focus. Grab the title bar of the 
window you want, and shake your mouse a little. All other windows will vanish into 
the task-bar. Repeat to undo and restore all of your hidden windows.

Thursday, November 4, 2010

change field data type into existing table in sql


change field data type into existing table in sql

alter table student
modify(stdAddress varchar2(50));

Wednesday, November 3, 2010

insert field into existing table in SQL


insert field into existing table in SQL
here table name is student
---------------------------------------

alter table student
add(stdAddress varchar2(25));

Tuesday, November 2, 2010

insert values into a table


insert values into a table
here student is table name



insert into student
values(01,'ABC','XII');

Monday, November 1, 2010

WAP function using a pointer to a function


/*WAP Invoking a function using a pointer to a function */
#include<stdio.h>
#include<conio.h>
main( )
{
 int  display( ) ;
 int  ( *func_ptr )( ) ;

 func_ptr = display ;  /* assign address of function */ 
 printf ( "\nAddress of function display is %u", func_ptr ) ;
 ( *func_ptr )( ) ;  /* invokes the function display( ) */
         getch();
}

int  display( )
{
 puts ( "\nLong live viruses!!" ) ;
}

Yahoo! Messenger Hidden Emoticons


Yahoo! Messenger Hidden Emoticons
puppy dog eyes :o3
I don't know - New! :-??
not listening - New! %-(
pig :@)
cow 3:-O
monkey :(|)
chicken ~:>
rose @};-
good luck %%-
flag **==
pumpkin (~~)
coffee ~O)
idea *-:)
skull 8-X
bug =:)
alien >-)
frustrated :-L
praying [-O<
money eyes $-)
whistling :-"
feeling beat up b-(
peace sign :)>-
shame on you [-X
dancing \:D/
bring it on >:/
hee hee ;))
chatterbox :-@
not worthy ^:)^
oh go on :-j
star (*)
hiro o->
billy o=>
april o-+
yin yang (%)

Sunday, October 31, 2010

Saturday, October 30, 2010

create table command in SQL


create table command

create table student(stdRollNo number, stdName varchar2(25), 
stdClass varchar2(25));

Tuesday, October 26, 2010

Hide your drives


Hide your drives

Note: do it on your own risk.



  • How to Hide the drives(c:,d:,e:,a:…etc) This is a great trick you can play on                                   your friends.  To disablethe display of local or networked drives when you                                        click MyComputer.
1.Go to start->run.Type regedit.Now go to:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion
\Policies\Explorer
  • Now in the right pane create a new DWORD item and name it                                                         NoDrives(it is case sensitive). 
 
  • Now modify it’s value and set it to 3FFFFFF (Hexadecimal) .
 
  • Now restart your computer. So, now when you click on My 
    Computer, no drives will be shown(all gone…). 
 
  • To enable display of drives in My Computer, simply delete this DWORD                                         item that you created.Again restart your computer.You can now see all the                                          drives again. Its cool Magic.

Protecting a folder using dos in windows98

Protecting a folder using dos in windows98

NOTE: do it on our own risk.



  • The following method works for windows98
  • with help of following method u can create folder that can not be accesed                                            from explorer , not even deletd .
  • folder that cannot be accessed from the Windows Explorer: Open MS-DOS                                       prompt, type mkdir followed by a space, then hold ALT key and type 251. Then release ALT
 
  • Now you can save there anything you want to hide. Windows 
    Explorer cannot display the content of this folder. You can 
    use these numbers instead of 251: 
    158, 159, 169, 176 to 224, 226 to 229, 231 to 240, 242 to 245, 
    247, 249, 252, 254 and 255.
    For me, only 176, 249, 251 and 254 worked. 
  • To access this folder from windows,
just rename it into a normal name. To do so, 
open MS-DOS, enter the directory, 
where your folder is placed and type ren followed by a space
then hold alt and type the number, that you used when you created 
your folder. Press space again and then type the new name of your 
folder. Press enter.
  • It's simple. Assuming ur file system is fat32 and u r using windows 98 second edition                           (i think it works in xp also). First go to the location using dos (either dos full mode or                           the ms-dos in windows start menu). Rename the folder using the ren command and                            rename it to ascii mode (with a secret code). U should not forget this code. No one else                        will can delete or open the folder.
Eg.: C:\ Games (this is the folder I've on my C drive)
I go to dos start->; programs ->; ms-dos 
dos window will open.
C:\ ren games Alt+158 (here we are renaming the games folder using the 
Alt key & a three digit number on the numpad (only numpad, it's 
important). U need to press the Alt key and the three digit code at a 
time. The code can be any three digit less than 255 (in my opinion) u can 
try Alt+164, Alt+176 etc. 

Ur folder is renamed & locked too at the same time

Now u won't see the games folder it'll be written in some ascii code 

Again to open the same go to dos and rename it using the ren command.

Eg: C\ ren Alt+158 games

Friday, October 8, 2010

WAP to using putch (),putchar (), fputchar (), putch (), fputchar ()


/*WAP to using putch (),putchar (), fputchar (), putch (), fputchar (),*/
#include<stdio.h>
#include<conio.h>
main( )
{
 char  ch = 'A' ;

 putch ( ch ) ; 
 putchar ( ch ) ;
 fputchar ( ch ) ;
 putch ( 'Z' ) ;
 putchar ( 'Z' ) ;
 fputchar ( 'Z' ) ;
       getch();
}

WAP of take user input for continue using getch( ), getche( ), getchar( ), fgetchar( )


/*WAP of take user input for continue using getch( ), getche( ), getchar( ), fgetchar( )*/
#include<stdio.h>
#include<conio.h>
main( )
{
 char  ch ;

 printf ( "\nPress any key to continue" ) ;
 getch( ) ;  /* will not echo the character */

 printf ( "\nType any character" ) ;
 ch = getche( ) ;  /* will echo the character typed */

 printf ( "\nType any character" ) ;
 getchar( ) ;  
/* will echo character, must be followed by enter key */ 
 printf ( "\nContinue Y/N" ) ;
 fgetchar( ) ;  
/* will echo character, must be followed by enter key */ 
       getch();
}

WAP to Formatting


/*WAP to Formatting*/
#include<stdio.h>
#include<conio.h>
main( )
{
 int  i = 10 ;
 char  ch = 'A' ;
 float  a = 3.14 ;
 char  str[20] ; 

 printf ( "\n%d %c %f", i, ch, a ) ;
 sprintf ( str, "%d %c %f", i, ch, a ) ;
 printf ( "\n%s", str ) ;
       getch();
}

WAP of Formatting2


/*WAP of Formatting2*/
#include<stdio.h>
#include<conio.h>
main( )
{
 char  ch = 'z' ;
 int  i = 125 ;
 float  a = 12.55 ;
 char  s[ ] = "hello there !" ;

 printf ( "\n%c %d %f", ch, ch, ch ) ;
 printf ( "\n%s %d %f", s, s, s ) ;
 printf ( "\n%c %d %f",i ,i, i ) ;
 printf ( "\n%f %d\n", a, a ) ;
       getch();
}

WAP to Formatting strings with 't' tab


/*WAP to Formatting strings with 't' tab */
#include<stdio.h>
#include<conio.h>
main( )
{
 printf ( "You\tmust\tbe\tcrazy\nto\thate\tthis\tbook" ) ;
       getch();
}

WAP to Formatting strings with printf( )


/*WAP to Formatting strings with printf( ) */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  firstname1[ ] = "Sandy" ;
 char  surname1[ ] = "Malya" ;
 char  firstname2[ ] = "AjayKumar" ;
 char  surname2[ ] = "Gurubaxani" ;

 printf ( "\n%20s%20s", firstname1, surname1 ) ;
 printf ( "\n%20s%20s", firstname2, surname2 ) ;
       getch();
}

WAP to formatting integer


/*WAP to formatting integer*/
#include<stdio.h>
#include<conio.h>
main( )
{
 int  weight = 63 ;

 printf ( "\nweight is %d kg", weight ) ;
 printf ( "\nweight is %2d kg", weight ) ;
 printf ( "\nweight is %4d kg", weight ) ;
 printf ( "\nweight is %6d kg", weight ) ;
 printf ( "\nweight is %-6d kg", weight ) ;
       getch();
}

Thursday, September 30, 2010

WAP to calculate sum of x-[x3/fact(3)]+[x5/fact(5)]...n terms


/*WAP to calculate sum of x-[x3/fact(3)]+[x5/fact(5)]...n terms*/
 
#include<stdio.h>
#include<conio.h>
void main()
{
      int d=1,i,x,n,fact=1;
      float s=0;
      clrscr();    // clear screen.
      printf("\nEnter value of x and n:");
      scanf("%d%d",&x,&n);
      for(i=1;i<=n*2-1;i++)   // loop executes n+2 times
      {
            d=d*x;                 // find x,x^2,x^3...
            fact=fact*i;          // count factorial of i
            if(i%2!=0)
                 s=s+(float)d/fact; //count sum only when i is odd
            else
                 d=-d;             // if even then d becomes -ve.
      }
      printf("The Sum of Series Is :%0.2f",s); // print result
      getch();
} 

Wednesday, September 29, 2010

WAP to use argc and argv


/*WAP to use argc and argv*/
#include<stdio.h>
#include<conio.h>
main ( int  argc, char  *argv[ ] )
{
 FILE  *fs, *ft ;
 char  ch ;

 if ( argc != 3 )
 {
  puts ( "Improper number of arguments" ) ;
  exit( ) ;
 }

 fs = fopen ( argv[1], "r" ) ;
 if ( fs == NULL )
 {
  puts ( "Cannot open source file" ) ;
  exit( ) ;
 }

 ft = fopen ( argv[2], "w" ) ;
 if ( ft == NULL )
 {
  puts ( "Cannot open target file" ) ;
  fclose ( fs ) ;
  exit( ) ;
 }

 while ( 1 )
 {
  ch = fgetc ( fs ) ;

  if ( ch == EOF )
   break ;
  else
   fputc ( ch, ft ) ;
 }

 fclose ( fs ) ;
 fclose ( ft ) ;
       getch();
}

WAP to Prints file contents on printer


/*WAP to Prints file contents on printer*/


#include<stdio.h>
#include<conio.h>
main( )
{
 FILE  *fp ;
 char  ch ; 

 fp = fopen ( "poem.txt", "r" ) ;

 if ( fp == NULL )
 {
  printf ( "Cannot open file" ) ;
  exit( ) ;
 }

 while ( ( ch = fgetc ( fp ) ) != EOF )
  fputc ( ch, stdprn ) ;
  
 fclose ( fp ) ;
}

Monday, September 27, 2010

WAP to File-copy which copies text, .com and .exe files


/*WAP to File-copy which copies text, .com and .exe files */
#include "fcntl.h"
#include "types.h"  /* if present in sys directory use 
          "c:tc\\include\\sys\\types.h" */
#include "stat.h"  /* if present in sys directory use 
         "c:\\tc\\include\\sys\\stat.h" */

main ( int  argc, char  *argv[ ] )
{
 char  buffer[ 512 ], source [ 128 ], target [ 128 ] ;
 int  inhandle, outhandle, bytes ;

 printf ( "\nEnter source file name" ) ;
 gets ( source ) ;

 inhandle = open ( source, O_RDONLY | O_BINARY ) ;
 if ( inhandle == -1 )
 {
  puts ( "Cannot open file" ) ;
  exit( ) ;
 }

 printf ( "\nEnter target file name" ) ;
 gets ( target ) ;

 outhandle = open ( target, O_CREAT | O_BINARY | O_WRONLY,       S_IWRITE ) ;
 if ( inhandle == -1 )
 {
  puts ( "Cannot open file" ) ;
  close ( inhandle ) ;
  exit( ) ;
 }

 while ( 1 )
 {
  bytes = read ( inhandle, buffer, 512 ) ;

  if ( bytes > 0 )
   write ( outhandle, buffer, bytes ) ;
  else 
   break ;
 }

 close ( inhandle ) ;
 close ( outhandle ) ;
}

WAP of A menu-driven program for elementary database management


/*WAP of A menu-driven program for elementary database management */

#include<stdio.h>
#include<conio.h>
main( )
{
 FILE  *fp, *ft ;
 char  another, choice ; 
 struct emp 
 {
  char  name[40] ;
  int  age ;
  float  bs ;
 } ;
 struct emp  e ;
 char  empname[40] ;
 long int  recsize ;

 fp = fopen ( "EMP.DAT", "rb+" ) ;

 if ( fp == NULL )
 {
  fp = fopen ( "EMP.DAT", "wb+" ) ;

  if ( fp == NULL )
  {
   puts ( "Cannot open file" ) ;
   exit( ) ;
  }
 }

 recsize = sizeof ( e ) ;

 while ( 1 )
 {
  clrscr( ) ;

  gotoxy ( 30, 10 ) ;
  printf ( "1. Add Records" ) ;
  gotoxy ( 30, 12 ) ;
  printf ( "2. List Records" ) ;
  gotoxy ( 30, 14 ) ;
  printf ( "3. Modify Records" ) ;
  gotoxy ( 30, 16 ) ;
  printf ( "4. Delete Records" ) ;
  gotoxy ( 30, 18 ) ;
  printf ( "0. Exit" ) ;
  gotoxy ( 30, 20 ) ;
  printf ( "Your choice" ) ;

  fflush ( stdin ) ;
  choice = getche( ) ;
  switch ( choice )
  {
   case '1' :

    fseek ( fp, 0 , SEEK_END ) ;
    another = 'Y' ;

    while ( another == 'Y' )
    {
   printf ( "\nEnter name, age and basic sal. " ) ;
    scanf ( "%s %d %f", e.name, &e.age, &e.bs ) ;
     fwrite ( &e, recsize, 1, fp ) ; 
    printf ( "\nAdd another Record (Y/N) " ) ;
     fflush ( stdin ) ;
     another = getche( ) ;
    }

    break ;
   
   case '2' :

    rewind ( fp ) ;

    while ( fread ( &e, recsize, 1, fp ) == 1 )
   printf ( "\n%s %d %f", e.name, e.age, e.bs ) ; 

    break ;

   case '3' :

    another = 'Y' ;
    while ( another == 'Y' )
    {
   printf ( "\nEnter name of employee to modify " ) ;
     scanf ( "%s", empname ) ;

     rewind ( fp ) ;
    while ( fread ( &e, recsize, 1, fp ) == 1 )
     {   
     if ( strcmp ( e.name, empname ) == 0 )
      {
    printf ( "\nEnter new name, age & bs" ) ;
    scanf ( "%s %d %f", e.name, &e.age,&e.bs ) ;
     fseek ( fp, - recsize, SEEK_CUR ) ; 
      fwrite ( &e, recsize, 1, fp ) ; 
       break ; 
      }
     }

    printf ( "\nModify another Record (Y/N) " ) ;
     fflush ( stdin ) ;
     another = getche( ) ;
    }

    break ;
   
   case '4' :

    another = 'Y' ;
    while ( another == 'Y' )
    {
   printf ( "\nEnter name of employee to delete " ) ;
     scanf ( "%s", empname ) ;

     ft = fopen ( "TEMP.DAT", "wb" ) ;

     rewind ( fp ) ;
    while ( fread ( &e, recsize, 1, fp ) == 1 )
     {
     if ( strcmp ( e.name, empname ) != 0 )
      fwrite ( &e, recsize, 1, ft ) ; 
     }

     fclose ( fp ) ;
     fclose ( ft ) ;
     remove ( "EMP.DAT" ) ;
     rename ( "TEMP.DAT", "EMP.DAT" ) ;

     fp = fopen ( "EMP.DAT", "rb+" ) ;

    printf ( "Delete another Record(Y/N) " ) ;
     fflush ( stdin ) ;
     another = getche( ) ;
    }
    break ;

   case '0' :
    fclose ( fp ) ;
    exit( ) ;
  }
 }
 getch();
}

WAP to Reads records from binary file and displays them on VDU


/*WAP to Reads records from binary file and displays them on VDU */
#include "stdio.h"
main( )
{
 FILE  *fp ;
 struct emp 
 {
  char  name[40] ;
  int  age ;
  float  bs ; 
 } ;
 struct emp  e ;

 fp = fopen ( "EMP.DAT", "rb" ) ;

 if ( fp == NULL )
 {
  puts ( "Cannot open file" ) ;
  exit( ) ;
 }

 while ( fread ( &e, sizeof ( e ), 1, fp ) == 1 )
  printf ( "\n%s %d %f", e.name, e.age, e.bs ) ; 

 fclose ( fp ) ;
}

WAP to Receives records from keyboard and writes them to a file in binary mode


/*WAP to Receives records from keyboard and writes
them to a file in binary mode */

#include "stdio.h"
main( )
{
 FILE  *fp ;
 char  another = 'Y' ; 
 struct emp 
 {
  char  name[40] ;
  int  age ;
  float  bs ;
 } ;
 struct emp  e ;
 
 fp = fopen ( "EMP.DAT", "wb" ) ;

 if ( fp == NULL )
 {
  puts ( "Cannot open file" ) ;
  exit( ) ;
 }

 while ( another == 'Y' )
 {
  printf ( "\nEnter name, age and basic salary: " ) ;
  scanf ( "%s %d %f", e.name, &e.age, &e.bs ) ;
  fwrite ( &e, sizeof ( e ), 1, fp ) ; 

  printf ( "Add another record (Y/N) " ) ;
  fflush ( stdin ) ;
  another = getche( ) ;
 }

 fclose ( fp ) ;
}

WAP to Read records from a file using structure


/*WAP to Read records from a file using structure */
#include "stdio.h"
main( )
{
 FILE  *fp ;
 struct emp 
 {
  char  name[40] ;
  int  age ;
  float  bs ;
 } ;
 struct emp  e ;

 fp = fopen ( "EMPLOYEE.DAT", "r" ) ;

 if ( fp == NULL )
 {
  puts ( "Cannot open file" ) ;
  exit( ) ;
 }

 while ( fscanf ( fp, "%s %d %f", e.name, &e.age, &e.bs ) != EOF )
  printf ( "\n%s %d %f", e.name, e.age, e.bs ) ; 

 fclose ( fp ) ;
}

WAP to Receives strings from keyboard and writes them to file


/*WAP to Receives strings from keyboard and writes them to file*/
#include "stdio.h"
main( )
{
 FILE  *fp ;
 char  s[80] ;

 fp = fopen ( "file1.TXT", "w" ) ;
 if ( fp == NULL )
 {
  puts ( "Cannot open file" ) ;
  exit( ) ;
 }

 printf ( "\nEnter a few lines of text:\n" ) ;
 while ( strlen ( gets ( s ) ) > 0 )
 {
  fputs ( s, fp ) ;
  fputs ( "\n", fp ) ;
 }
 
 fclose ( fp ) ;
}

WAP to read a file and write(copy) data in another file


/*WAP to read a file and write(copy) data in another file*/
#include<stdio.h>
#include<conio.h>
main( )
{
 FILE  *fs, *ft ;
 char  ch ;

 fs = fopen ( "pr1.c", "r" ) ;
 if ( fs == NULL )
 {
  puts ( "Cannot open source file" ) ;
  exit( ) ;
 }

 ft = fopen ( "pr2.c", "w" ) ;
 if ( ft == NULL )
 {
  puts ( "Cannot open target file" ) ;
  fclose ( fs ) ;
  exit( ) ;
 }

 while ( 1 )
 {
  ch = fgetc ( fs ) ;

  if ( ch == EOF )
   break ;
  else
   fputc ( ch, ft ) ;
 }

 fclose ( fs ) ;
 fclose ( ft ) ;
       getch();
}

WAP to Count chars, spaces, tabs and newlines in a file


/*WAP to Count chars, spaces, tabs and newlines in a file*/
#include<stdio.h>
#include<conio.h>
main( )
{
 FILE  *fp ;
 char  ch ;
 int  nol = 0, not = 0, nob = 0, noc = 0 ;
 
 fp = fopen ( "PR1.C", "r" ) ;

 while ( 1 )
 {
  ch = fgetc ( fp ) ;

  if ( ch == EOF )
   break ;

  noc++ ;

  if ( ch == '  ' )
   nob++ ;

  if ( ch == '\n' )
   nol++ ;

  if ( ch == '\t' )
   not++ ;
 }

 fclose ( fp ) ;
 printf ( "\nNumber of characters = %d", noc ) ;
 printf ( "\nNumber of blanks = %d", nob ) ;
 printf ( "\nNumber of tabs = %d", not ) ;
 printf ( "\nNumber of lines = %d", nol ) ;
       getch();
}


WAP to check existing file empty or not


/*WAP to check existing file empty or not*/
#include<stdio.h>
#include<conio.h>
main( )
{
 FILE  *fp ;

 fp = fopen ( "PR1.C", "r" ) ;
 if ( fp == NULL )
 {
  puts ( "cannot open file" ) ;
  exit( ) ;
 }
       getch();
}

WAP to Display contents of a file on screen


/*WAP to Display contents of a file on screen*/
#include<stdio.h>
#include<conio.h>

main( )
{
 FILE  *fp ;
 char  ch ;
 
 fp = fopen ( "PR1.C", "r" ) ;

 while ( 1 )
 {
  ch = fgetc ( fp ) ;

  if ( ch == EOF )
   break ;

  printf ( "%c", ch ) ;
 }

 fclose ( fp ) ;
  getch();
}

WAP to that includes a method inside a class



/*WAP to that includes a method inside a class*/
class Box {
double width;
double height;
double depth;
// display volume of a box
void volume() {
System.out.print("Volume is ");
System.out.println(width * height * depth);
}
}
class BoxDemo3 {
public static void main(String args[]) {
Box mybox1 = new Box();
Box mybox2 = new Box();
// assign values to mybox1's instance variables
mybox1.width = 10;
mybox1.height = 20;
mybox1.depth = 15;
/* assign different values to mybox2's
instance variables */
mybox2.width = 3;
mybox2.height = 6;
mybox2.depth = 9;
// display volume of first box
mybox1.volume();
// display volume of second box
mybox2.volume();
}
}

WAP to declares two Box class objects




/*WAP to declares two Box class objects*/
class Box {
double width;
double height;
double depth;
}
class BoxDemo2 {
public static void main(String args[]) {
Box mybox1 = new Box();
Box mybox2 = new Box();
double vol;
// assign values to mybox1's instance variables
mybox1.width = 10;
mybox1.height = 20;
mybox1.depth = 15;
/* assign different values to mybox2's
instance variables */
mybox2.width = 3;
mybox2.height = 6;
mybox2.depth = 9;
// compute volume of first box
vol = mybox1.width * mybox1.height * mybox1.depth;
System.out.println("Volume is " + vol);
// compute volume of second box
vol = mybox2.width * mybox2.height * mybox2.depth;
System.out.println("Volume is " + vol);
}
}

WAP that calculate volume of Box


/*WAP that calculate volume of Box
Save as BoxDemo.java
*/
class Box {
double width;
double height;
double depth;
}
// This class declares an object of type Box.
class BoxDemo {
public static void main(String args[]) {
Box mybox = new Box();
double vol;
// assign values to mybox's instance variables
mybox.width = 10;
mybox.height = 20;
mybox.depth = 15;
// compute volume of box
vol = mybox.width * mybox.height * mybox.depth;
System.out.println("Volume is " + vol);
}
}

Friday, September 24, 2010

WAP to Passing address of a structure variable


/*WAP to Passing address of a structure variable */
#include<stdio.h>
#include<conio.h>
struct book 
{
 char  name[25] ;
 char  author[25] ;
 int  callno ;
} ;

main( )
{
 struct book  b1 = { "Let us C", "YPK", 101 } ;
 display ( &b1 ) ;
       getch();
}

display ( struct book  *b )
{
 printf ( "\n%s %s %d", b->name, b->author, b->callno ) ;
}

WAP to Passing individual structure elements


/*WAP to Passing individual structure elements */
#include<stdio.h>
#include<conio.h>
main( )
{
 struct book 
 {
  char  name[25] ;
  char  author[25] ;
  int  callno ;
 } ;
 struct book b1 = { "Let us C", "YPK", 101 } ;
 
 display ( b1.name, b1.author, b1.callno ) ;
 getch();
}

display ( char  *s, char  *t, int  n )
{
 printf ( "\n%s %s %d", s, t, n ) ;
}

WAP take people datail using structure


/*WAP take people datail using structure*/
#include<stdio.h>
#include<conio.h>
main( )
{
 struct address
 {
  char  phone[15] ;
  char  city[25] ;
  int  pin ;
 } ;

 struct emp
 {
  char  name[25] ;
  struct address  a ;
 } ;
 struct emp  e = { "jeru", "531046", "nagpur", 10 }; 

 printf ( "\nname = %s phone = %s", e.name, e.a.phone ) ;
 printf ( "\ncity = %s pin = %d", e.a.city, e.a.pin ) ;
       getch();
}

WAP Using a do-while loop to process a menu selection


/*WAP Using a do-while loop to process a menu selection
save file as: Menu.java
*/
class Menu {
public static void main(String args[])
throws java.io.IOException {
char choice;
do {
System.out.println("Help on:");
- 84 -
System.out.println(" 1. if");
System.out.println(" 2. switch");
System.out.println(" 3. while");
System.out.println(" 4. do-while");
System.out.println(" 5. for\\n");
System.out.println("Choose one:");
choice = (char) System.in.read();
} while( choice < '1' || choice > '5');
System.out.println("\\n");
switch(choice) {
case '1':
System.out.println("The if:\\n");
System.out.println("if(condition) statement;");
System.out.println("else statement;");
break;
case '2':
System.out.println("The switch:\\n");
System.out.println("switch(expression) {");
System.out.println(" case constant:");
System.out.println(" statement sequence");
System.out.println(" break;");
System.out.println(" // ...");
System.out.println("}");
break;
case '3':
System.out.println("The while:\\n");
System.out.println("while(condition) statement;");
break;
case '4':
System.out.println("The do-while:\\n");
System.out.println("do {");
System.out.println(" statement;");
System.out.println("} while (condition);");
break;
case '5':
System.out.println("The for:\\n");
System.out.print("for(init; condition; iteration)");
System.out.println(" statement;");
break;
}
}
}

WAP to An improved version of the season program


/*WAP to An improved version of the season program*/
class Switch {
public static void main(String args[]) {
int month = 4;
String season;
switch (month) {
case 12:
case 1:
case 2:
season = "Winter";
break;
case 3:
case 4:
case 5:
season = "Spring";
break;
case 6:
case 7:
case 8:
season = "Summer";
break;
case 9:
case 10:
case 11:
season = "Autumn";
break;
default:
season = "Bogus Month";
}
System.out.println("April is in the " + season + ".");
}
}

WAP to check that In a switch, break statements are optional


/*WAP to check that In a switch, break statements are optional*/
class MissingBreak {
public static void main(String args[]) {
for(int i=0; i<12; i++)
switch(i) {
case 0:
case 1:
case 2:
case 3:
case 4:
System.out.println("i is less than 5");
break;
case 5:
case 6:
case 7:
case 8:
case 9:
System.out.println("i is less than 10");
break;
default:
System.out.println("i is 10 or more");
}
}
}

Thursday, September 23, 2010

WAP to Usage of an array of structures


/*WAP to Usage of an array of structures */
#include<stdio.h>
#include<conio.h>
main( )
{
 struct book
 {
  char  name ;
  float  price ;
  int  pages ;
 } ;

 struct book  b[100] ;
 int  i ;

 for ( i = 0 ; i <= 99 ; i++ )
 {
  printf ( "\nEnter name, price and pages " ) ;
  scanf ( "%c %f %d", &b[i].name, &b[i].price, &b[i].pages ) ;
 }

 for ( i = 0 ; i <= 99 ; i++ )
  printf ( "\n%c %f %d", b[i].name, b[i].price, b[i].pages ) ;
       getch();
}

linkfloat( )
{
      float a = 0, *b ;
 b = &a ;  /* cause emulator to be linked */
      a = *b ;    /* suppress the warning - variable not used */
}

WAP to Memory map of structure elements


/*WAP to Memory map of structure elements */
#include<stdio.h>
#include<conio.h>
main( )
{
 struct book
 { 
  char  name ;
  float  price ;
  int  pages ;
 } ;
 struct book  b1 = { 'B', 130.00, 550 } ;
 
 printf ( "\nAddress of name = %u", &b1.name ) ;
 printf ( "\nAddress of price = %u", &b1.price ) ;
 printf ( "\nAddress of pages = %u", &b1.pages ) ;
       getch();
}

WAP to take book datails using structure


/*WAP to take book datails using structure*/
#include<stdio.h>
#include<conio.h>
main( )
{
 struct book
 { 
  char  name ;
  float  price ;
  int  pages ;
 } ;
 struct book  b1, b2, b3 ;

 printf ( "\nEnter names, prices & no. of pages of 3 books\n" ) ;
 scanf ( "%c %f %d", &b1.name, &b1.price, &b1.pages ) ;
 scanf ( "%c %f %d", &b2.name, &b2.price, &b2.pages ) ;
 scanf ( "%c %f %d", &b3.name, &b3.price, &b3.pages ) ;

 printf ( "\nAnd this is what you entered" ) ;
 printf ( "\n%c %f %d", b1.name, b1.price, b1.pages ) ;
 printf ( "\n%c %f %d", b2.name, b2.price, b2.pages ) ;
 printf ( "\n%c %f %d", b3.name, b3.price, b3.pages ) ;
       getch();
}

WAP to take books detail


/*WAP to take books detail*/
#include<stdio.h>
#include<conio.h>
main( )
{
 char  name[3] ;
 float  price[3] ;
 int  pages[3], i ;

 printf ( "\nEnter names, prices and no. of pages of 3 books\n" ) ;

 for ( i = 0 ; i <= 2 ; i++ )
  scanf ( "%c %f %d", &name[i], &price[i], &pages[i] );

 printf ( "\nAnd this is what you entered\n" ) ;
 for ( i = 0 ; i <= 2 ; i++ )
  printf ( "%c %f %d\n", name[i], price[i], pages[i] );
       getch();
}

Tuesday, September 21, 2010

WAP to Demonstrate switch statements


/*WAP to Demonstrate switch statements*/
class SampleSwitch {
public static void main(String args[]) {
for(int i=0; i<6; i++)
switch(i) {
case 0:
System.out.println("i is zero.");
break;
case 1:
System.out.println("i is one.");
break;
case 2:
System.out.println("i is two.");
break;
case 3:
System.out.println("i is three.");
break;
default:
System.out.println("i is greater than 3.");
}
}
}

WAP to Demonstrate if-else-if statements


/*WAP to Demonstrate if-else-if statements*/
class IfElse {
public static void main(String args[]) {
int month = 4; // April
String season;
if(month == 12 || month == 1 || month == 2)
season = "Winter";
else if(month == 3 || month == 4 || month == 5)
season = "Spring";
else if(month == 6 || month == 7 || month == 8)
season = "Summer";
else if(month == 9 || month == 10 || month == 11)
season = "Autumn";
else
season = "Bogus Month";
System.out.println("April is in the " + season + ".");
}
}

WAP to Demonstrate ? : Ternary operator


/*WAP to Demonstrate ? : Ternary operator*/
class Ternary {
public static void main(String args[]) {
int i, k;
i = 10;
k = i < 0 ? -i : i; // get absolute value of i
System.out.print("Absolute value of ");
System.out.println(i + " is " + k);
i = -10;
k = i < 0 ? -i : i; // get absolute value of i
System.out.print("Absolute value of ");
System.out.println(i + " is " + k);
}
}

WAP to Demonstrate the boolean logical operators


/*WAP to Demonstrate the boolean logical operators*/
class BoolLogic {
public static void main(String args[]) {
boolean a = true;
boolean b = false;
boolean c = a | b;
boolean d = a & b;
boolean e = a ^ b;
boolean f = (!a & b) | (a & !b);
boolean g = !a;
System.out.println(" a = " + a);
System.out.println(" b = " + b);
System.out.println(" a|b = " + c);
System.out.println(" a&b = " + d);
System.out.println(" a^b = " + e);
System.out.println("!a&b|a&!b = " + f);
System.out.println(" !a = " + g);
}
}

WAP of bit


/*WAP of bit*/
class OpBitEquals {
public static void main(String args[]) {
int a = 1;
int b = 2;
int c = 3;
a |= 4;
b >>= 1;
c <<= 1;
a ^= c;
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
}
}

Monday, September 20, 2010

WAP to use array of pointers and Use of malloc


/*WAP to use array of pointers */
/* and Use of malloc */

#include<stdio.h>
#include<conio.h>
#include "alloc.h"
main( )
{
 char  *names[6] ;
 char n[50] ;
 int  len, i ;
 char *p ;

 for ( i = 0 ; i <= 5 ; i++ )
 {
  printf ( "\nEnter name " ) ;
  scanf ( "%s", n ) ;
  len = strlen ( n ) ;
  p = malloc ( len + 1 ) ;
  strcpy ( p, n ) ;
  names[i] = p ;
 }

 for ( i = 0 ; i <= 5 ; i++ )
  printf ( "\n%s", names[i] ) ;
}

WAP to interchange string3 with string4


/*WAP to interchange string3 with string4*/
#include<stdio.h>
#include<conio.h>
main( )
{
 char  *names[ ] = {
      "akshay",
      "parag",
      "raman",
      "srinivas",
      "gopal",
      "rajesh"
   } ;
 char  *temp ;

 printf ( "Original: %s %s", names[2], names[3] ) ;

 temp = names[2] ;
 names[2] = names[3] ;
 names[3] = temp ;

 printf ( "\nNew: %s %s", names[2], names[3] ) ;
}

WAP to Exchange names using 2-D array of characters


/*WAP to Exchange names using 2-D array of characters */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  names[ ][10] = {
      "akshay",
      "parag",
      "raman",
      "srinivas",
      "gopal",
      "rajesh"
        } ;
 int  i ;
 char  t ;

 printf ( "\nOriginal: %s %s", &names[2][0], &names[3][0] ) ;  

 for ( i = 0 ; i <= 9 ; i++ )
 {
  t = names[2][i] ;
  names[2][i] = names[3][i] ;
  names[3][i] = t ;
 }

 printf ( "\nNew: %s %s", &names[2][0], &names[3][0] ) ;
}

WAP to search a string in two dimensional array


/*WAP to search a string in two dimensional array */
#include<stdio.h>
#include<conio.h>
#define FOUND 1
#define NOTFOUND 0
main( )
{
 char  masterlist[6][10] = {
       "akshay",
       "parag",
       "raman",
       "srinivas",
       "gopal",
       "rajesh"
         } ;
 int  i, flag, a ;
 char  yourname[10] ;
 printf ( "\nEnter your name " ) ;
 scanf ( "%s", yourname ) ;

 flag = NOTFOUND ;
 for ( i = 0 ; i <= 5 ; i++ )
 {
  a = strcmp ( &masterlist[i][0], yourname ) ;
  if ( a == 0 )
  {
   printf ( "Welcome, you can enter the palace" ) ;
   flag = FOUND ;
   break ;
  }
 }

 if ( flag == NOTFOUND )
  printf ( "Sorry, you are a trespasser" ) ;
}

WAP to Use of strcmp() function


/*WAP to Use of strcmp() function */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  string1[ ] = "Jerry" ;
 char  string2[ ] = "Ferry" ;
 int  i, j, k ;

 i = strcmp ( string1, "Jerry" ) ;
 j = strcmp ( string1, string2 ) ;
 k = strcmp ( string1, "Jerry boy" ) ;

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

WAP to Use of strcat() function


/*WAP to Use of strcat() function */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  source[ ] = "Folks!" ;
 char  target[30] = "Hello" ;

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

WAP to Use of const keyword


/*WAP to Use of const keyword */
#include<stdio.h>
#include<conio.h>
main( )
{
 float r, a ;
 const float pi = 3.14 ;

 printf ( "\nEnter radius of circle " ) ;
 scanf  ( "%f", &r ) ;
 a = pi * r * r ;
 printf ( "\nArea of circle = %f", a ) ;
}

WAP to copy string without changing source string


/*WAP to copy string without changing source string */
#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 ) ;
}

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

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);
}
}

Saturday, September 18, 2010

WAP to Using pointer to access array elements


/*WAP to Using pointer to access array elements */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  name[ ] = "Goldfish" ;
 char  *ptr ;

 ptr = name ;  /* store base address of string */

 while ( *ptr != `\0' )
 {
  printf ( "%c", *ptr ) ;
  ptr++ ;
 }
}

WAP to demonstrate printing of string 2


/*WAP to demonstrate printing of string 2*/
#include<stdio.h>
#include<conio.h>
main( )
{
 char  name[ ] = "Klinsman" ;
 int  i = 0 ;

 while ( name[i] != `\0' )
 {
  printf ( "%c", name[i] ) ;
  i++ ;
 }
}

WAP to demonstrate printing of a string


/*WAP to demonstrate printing of a string */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  name[ ] = "Goldfish" ;
 int  i = 0 ;

 while ( i <= 9 )
 {
  printf ( "%c", name[i] ) ;
  i++ ;
 }
}

WAP to Usage of pointer to an array


/*WAP to Usage of pointer to an array */
#include<stdio.h>
#include<conio.h>
main( )
{
 int  s[5][2] = {
     { 1234, 56 },
     { 1212, 33 },
     { 1434, 80 },
     { 1312, 78 }
       } ;  
 int  ( *p )[2] ;
 int  i, j, *pint ;
 
 for ( i = 0 ; i <= 3 ; i++ )
 {
   p = &s[i] ;
  pint = p ;
  printf ( "\n" ) ;
  for ( j = 0 ; j <= 1 ; j++ )
   printf ( "%d ", *( pint + j ) ) ; 
 }
}

WAP to Accessing array elements in different ways


/*WAP to Accessing array elements in different ways */
#include<stdio.h>
#include<conio.h>
main( )
{
 int  num[ ] = { 24, 34, 12, 44, 56, 17 } ;
 int  i ;

 for ( i = 0 ; i <= 5 ; i++ )
 {
  printf ( "\naddress = %u ", &num[i] ) ;
  printf ( "element = %d %d ", num[i], *( num + i ) ) ; 
  printf ( "%d %d", *( i + num ), i[num] ) ;
 }
}

Thursday, September 16, 2010

WAP to access array elements


/*WAP to access array elements */
#include<stdio.h>
#include<conio.h>
main( )
{
 int  num[ ] = { 24, 34, 12, 44, 56, 17 } ;
 int  i ;

 for ( i = 0 ; i <= 5 ; i++ )
 {
  printf ( "\naddress = %u ", &num[i] ) ;
  printf ( "element = %d", num[i] ) ;
 }
}

WAP to print out the memory locations


/*WAP to print out the memory locations*/
#include<stdio.h>
#include<conio.h>
main( )
{
 int  num[ ] = { 24, 34, 12, 44, 56, 17 } ;
 int  i ;

 for ( i = 0 ; i <= 5 ; i++ )
 {
  printf ( "\nelement no. %d ", i ) ;
  printf ( "address = %u", &num[i] ) ;
 }
}

WAP to Comparison of two pointer variables


/*WAP to Comparison of two pointer variables */
#include<stdio.h>
#include<conio.h>
main( )
{
 int  arr[ ] = { 10, 20, 36, 72, 45, 36 } ;
 int  *j, *k ;

 j = &arr [ 4 ] ;
 k = ( arr + 4 ) ;

 if ( j == k )
  printf ( "The two pointers point to the same location" ) ;
 else
  printf ( "The two pointers do not point to the same location" ) ;
}

WAP to Subtraction of one pointer from another


/*WAP to Subtraction of one pointer from another*/
#include<stdio.h>
#include<conio.h>
main( )
{
 int  arr[ ] = { 10, 20, 30, 45, 67, 56, 74 } ;
 int  *i, *j ;

 i = &arr[1] ;
 j = &arr[5] ;
 printf ( "%d %d", j - i, *j - *i ) ;
}

WAP to Introducing pointers


/*WAP to Introducing pointers */
#include<stdio.h>
#include<conio.h>
main( )
{
 int  i = 3, *x ;
 float  j = 1.5, *y ;
 char  k = 'c', *z ;

 printf ( "\nValue of i = %d", i ) ;
 printf ( "\nValue of j = %f", j ) ;
 printf ( "\nValue of k = %c", k ) ;
 x = &i ;
 y = &j ;
 z = &k ;
 printf ( "\nOriginal address in x = %u", x ) ;
 printf ( "\nOriginal address in y = %u", y ) ;
 printf ( "\nOriginal address in z = %u", z ) ;
 x++ ;
 y++ ;
 z++ ;
 printf ( "\nNew address in x = %u", x ) ;
 printf ( "\nNew address in y = %u", y ) ;
 printf ( "\nNew address in z = %u", z ) ;
}


WAP to pass an array to a function by address


/*WAP to pass an array to a function by address*/
#include<stdio.h>
#include<conio.h>
main( )
{
 int  i ;
 int  marks[ ] = { 55, 65, 75, 56, 78, 78, 90 } ;

 for ( i = 0 ; i <= 6 ; i++ )
  disp ( &marks[i] ) ;
}

disp ( int  *n )
{
 show ( &n ) ;
}

show ( int  *m )
{
 printf("%d  ",*m)
}

WAP to Demonstration of call by value


/*WAP to Demonstration of call by value*/
#include<stdio.h>
#include<conio.h>
main( )
{
 int  i ;
 int  marks[ ] = { 55, 65, 75, 56, 78, 78, 90 } ;

 for ( i = 0 ; i <= 6 ; i++ )
  display ( marks[i] ) ;
} 

display ( int  m )
{
 printf ( "%d ", m ) ;
}

Wednesday, September 15, 2010

WAP to Demonstrate the basic arithmetic operators


/*WAP to Demonstrate the basic arithmetic operators*/
class BasicMath {
public static void main(String args[]) {
// arithmetic using integers
System.out.println("Integer Arithmetic");
int a = 1 + 1;
int b = a * 3;
int c = b / 4;
int d = c - a;
int e = -d;
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
System.out.println("d = " + d);
System.out.println("e = " + e);
// arithmetic using doubles
System.out.println("\\nFloating Point Arithmetic");
double da = 1 + 1;
double db = da * 3;
double dc = db / 4;
double dd = dc - a;
double de = -dd;
System.out.println("da = " + da);
System.out.println("db = " + db);
System.out.println("dc = " + dc);
System.out.println("dd = " + dd);
System.out.println("de = " + de);
}
}

WAP to Demonstrate a three-dimensional array


/*WAP to Demonstrate a three-dimensional array*/
class threeDMatrix {
public static void main(String args[]) {
int threeD[][][] = new int[3][4][5];
int i, j, k;
for(i=0; i<3; i++)
for(j=0; j<4; j++)
for(k=0; k<5; k++)
threeD[i][j][k] = i * j * k;
for(i=0; i<3; i++) {
for(j=0; j<4; j++) {
for(k=0; k<5; k++)
System.out.print(threeD[i][j][k] + " ");
System.out.println();
}
System.out.println();
}
}
}

Tuesday, September 14, 2010

WAP to Use of # pragma 2


/*WAP to Use of # pragma */
/* Pogram to supress specific warning */
#include<stdio.h>
#include<conio.h>
#pragma warn -rvl /* return value */
#pragma warn -par /* parameter not used */ 
#pragma warn -rch /* unreachable code */

int  f1( )
{
 int  a = 5 ;
}

void  f2 ( int  x )
{
 printf ( "\nInside f2" ) ;
}

int  f3( )
{
 int  x = 6 ;
 return x ;
 x++  ;
}

void  main( )
{
 f1( ) ;
 f2 (  7 ) ;
 f3( ) ;
 getch();
}

WAP to Use of #pragma


/*WAP to Use of #pragma */
/* Program to change execution of functions */
#include<stdio.h>
#include<conio.h>
void fun1( ) ;
void fun2( ) ;

#pragma startup fun1
#pragma exit fun2

main( )
{
 printf ( "\nInside maim" ) ;
 getch();
}

void fun1( )
{
 printf ( "\nInside fun1" ) ;
}

void fun2( )
{
 printf ( "\nInside fun2" ) ;
}

WAP to Multiple line in macros expansion


/*WAP to Multiple line in macros expansion*/
/* Program to draw horizontal & vertical line */
#include<stdio.h>
#include<conio.h>
#define HLINE   for ( i = 0 ; i < 79 ; i++ ) \  
                             printf ( "%c", 196 ) ;

#define VLINE( X, Y )  {\gotoxy ( X, Y ) ; \
       printf ( "%c", 179 ) ; \
     }
main( )
{
 int  i, y ;
 clrscr( ) ;

 gotoxy ( 1, 12 ) ;
 HLINE

 for ( y = 1 ; y < 25 ; y++ )
  VLINE ( 39, y ) ;
 getch();
}


WAP to Macros expansion with arguments


/*WAP to Macros expansion with arguments */
/* Program to test whether entered character is digit */
#define ISDIGIT(y) ( y >= 48 && y <= 57 )
main( )
{
 char  ch ;

 printf ( "Enter any digit " ) ;
 scanf ( "%c", &ch ) ;

 if ( ISDIGIT ( ch ) )
  printf ( "\nYou entered a digit" ) ;
 else
  printf ( "\nIllegal input" ) ;
       getch();
} 


WAP to use Macros expansion with arguments


/*WAP to use Macros expansion with arguments */
#include<stdio.h>
#include<conio.h>
#define AREA(x) ( 3.14 * x * x )
main( )
{
 float  r1 = 6.25, r2 = 2.5, a ;
 
 a = AREA ( r1 ) ;
 printf ( "\nArea of circle = %f", a ) ;
 a = AREA ( r2 ) ;
 printf ( "\nArea of circle = %f", a ) ;
       getch();
}

WAP to # define statement used to replace entire C statement


/*WAP to # define statement used to replace entire C statement */
#include<stdio.h>

#define FOUND printf ( "The Yankee Doodle Virus" ) ;
main( )
{
 char  signature ;

 if ( signature == 'Y' ) 
  FOUND
 else
  printf ( "Safe... as yet !" ) ;
 getch();
}


WAP to Nested macro expansion


/*WAP to Nested macro expansion*/
#include<stdio.h>
#include<conio.h>
#define AND &&
#define ARANGE ( a > 25 AND a < 50 )
main( )
{
 int  a = 30 ;

 if ( ARANGE )
  printf ( "within range" ) ;
 else
  printf ( "out of range" ) ;
 getch();
}

WAP to use Macro expansion Logical operator


/*WAP to use Macro expansion Logical operator*/
#include<stdio.h>
#include<conio.h>
#define AND &&
#define OR  ||
main( )
{
 int  f = 1, x = 4, y = 90 ;

 if ( ( f < 5 ) AND ( x <= 20 OR y <= 45 ) )
  printf ( "\nYour PC will always work fine..." ) ;
 else
  printf ( "\nIn front of the maintenance man" ) ;
 getch();
}

WAP to Use of macro expansion2


/*WAP to Use of macro expansion*/
#include<stdio.h>
#include<conio.h>
#define PI  3.1415
main( )
{
 float  r = 6.25 ;
 float  area ;

 area = PI * r * r ;
 printf ( "\nArea of circle = %f", area ) ;
 getch();
}

WAP to Use of macro expansion


/*WAP to Use of macro expansion*/
#include<stdio.h>
#include<conio.h>
#define UPPER 25
main( )
{
 int  i ;
 for ( i = 1 ; i <= UPPER ; i++ )
  printf ( "\n%d", i ) ;
}

WAP to Use of continue keyword in for loop


/*WAP to Use of continue keyword in for loop */
#include<stdio.h>
#include<conio.h>
main( )
{
 int   i, j ;

 for ( i = 1 ; i <= 2 ; i++ )
 {
  for ( j = 1 ; j <= 2 ; j++ )
  {
   if ( i == j )
    continue ;

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

Execution of a loop an unknown number of times


/* Execution of a loop an unknown number of times */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  another ;
 int  num ;
 do
 {
  printf ( "Enter a number " ) ;
  scanf ( "%d", &num ) ;
  printf ( "square of %d is %d", num, num * num ) ;
  printf ( "\nWant to enter another number y/n " ) ;
  scanf ( " %c", &another ) ;
 } while ( another == 'y' ) ;
 getch();
}


WAP to Demonstration of nested loops


/*WAP to Demonstration of nested loops */
#include<stdio.h>
#include<conio.h>
main( )
{
 int   r, c, sum ;
 for ( r = 1 ; r <= 3 ; r++ )  /* outer loop */
 {
  for ( c = 1 ; c <= 2 ; c++ )  /* inner loop */
  {
   sum = r + c ;
   printf ( "r = %d c = %d sum = %d\n", r, c, sum ) ;
  }
 }
 getch();
}


WAP to Shape


/*WAP to Shape*/
#include<stdio.h>
#include<conio.h> 
void main()
{
int i,j,n;
clrscr();  //clear screen

for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
printf("%d ",i);
printf("\n");
}
getch();
}

WAP to shap


/*WAP to shap3*/
#include<stdio.h>
#include<conio.h> 
void main()
{
 int i,j;
clrscr();   //clear screen
for(i=5;i>=1;i--)   //loop starts from n for row
{
for(j=1;j<=i;j++)  // loop executes i times for colom
printf("%d",j);   // print j
printf("\n");   // goto next line
}
getch();
}

WAP to Demonstrate casts


/*WAP to Demonstrate casts*/
class Conversion {
public static void main(String args[]) {
byte b;
int i = 257;
double d = 323.142;
System.out.println("\\nConversion of int to byte.");
b = (byte) i;
System.out.println("i and b " + i + " " + b);
System.out.println("\\nConversion of double to int.");
i = (int) d;
System.out.println("d and i " + d + " " + i);
System.out.println("\\nConversion of double to byte.");
b = (byte) d;
System.out.println("d and b " + d + " " + b);
}
getch();
}

WAP to Demonstrate dynamic initialization


/*WAP to Demonstrate dynamic initialization*/
class DynInit {
public static void main(String args[]) {
double a = 3.0, b = 4.0;
// c is dynamically initialized
double c = Math.sqrt(a * a + b * b);
System.out.println("Hypotenuse is " + c);
}
getch();
}

WAP to Demonstrate boolean values


/*WAP to Demonstrate boolean values*/
class BoolTest {
public static void main(String args[]) {
boolean b;
b = false;
System.out.println("b is " + b);
b = true;
System.out.println("b is " + b);
// a boolean value can control the if statement
if(b) System.out.println("This is executed.");
b = false;
if(b) System.out.println("This is not executed.");
// outcome of a relational operator is a boolean value
System.out.println("10 > 9 is " + (10 > 9));
}
}

Monday, September 13, 2010

WAP ot calculate salary of an employee


/*WAP ot calculate salary of an employee */
#include<stdio.h>
#include<conio.h>
main( )
{
 char   g ;
 int   yos, qual, sal ;

 printf ( "Enter Gender, Years of Service and 
   Qualifications ( 0 = G, 1 = PG ):" ) ;
 scanf ( "%c%d%d", &g, &yos, &qual ) ;

 if ( g == 'm' && yos >= 10 && qual == 1 )
  sal = 15000 ;
 else if ( ( g == 'm' && yos >= 10 && qual == 0 ) || 
  ( g == 'm' && yos < 10 && qual == 1 ) )
  sal = 10000 ;
 else if ( g == 'm' && yos < 10 && qual == 0 )
  sal = 7000 ;
 else if ( g == 'f' && yos >= 10 && qual == 1 )
  sal = 12000 ;
 else if ( g == 'f' && yos >= 10 && qual == 0 )
  sal = 9000 ;
 else if ( g == 'f' && yos < 10 && qual == 1 )
  sal = 10000 ; 
 else if ( g == 'f' && yos < 10 && qual == 0 )
  sal = 6000 ;

 printf ( "\nSalary of Employee = %d", sal ) ;
 getch();
}

Insurance of driver - using logical operators - 2


/* Insurance of driver - using logical operators */
#include<stdio.h>
#include<conio.h>
main( )
{
 char   sex, ms ;
 int   age ;

 printf ( "Enter age, sex, marital status " ) ;
 scanf ( "%d %c %c" &age, &sex, &ms ) ; 

 if ( ( ms == 'M') || ( ms == 'U' && sex == 'M' && age > 30 ) || 
    ( ms == 'U' && sex == 'F' && age > 25 ) )
  printf ( "Driver is insured" ) ;
 else
  printf ( "Driver is not insured" ) ;
 getch();
}

Insurance of driver - without using logical operators


/* Insurance of driver - without using logical operators */
#include<stdio.h>
#include<conio.h>
main( )
{
 char   sex, ms ;
 int   age ;

 printf ( "Enter age, sex, marital status " ) ;
 scanf ( "%d %c %c", &age, &sex, &ms ) ;

 if ( ms == 'M' ) 
  printf ( "Driver is insured" ) ;
 else
 {
  if ( sex == 'M' )
  {
   if ( age > 30 )
    printf ( "Driver is insured" ) ;
   else 
    printf ( "Driver is not insured" ) ;
  }
  else
  {
   if ( age > 25 )
    printf ( "Driver is insured" ) ;
   else 
    printf ( "Driver is not insured" ) ;
  }
 }
 getch();
}

WAP of nested if-else


/*WAP of nested if-else */
#include<stdio.h>
#include<conio.h>
main( )
{
 int   i ;

 printf ( "Enter either 1 or 2 " ) ;
 scanf ( "%d", &i ) ;

 if ( i == 1 )
  printf ( "You would go to heaven !" ) ;
 else
 {
  if ( i == 2 )
   printf ( "Hell was created with you in mind" ) ;
  else
   printf ( "How about mother earth !" ) ;
 }
getch();
}

WAP to Calculation of gross salary


/*WAP to Calculation of gross salary */
#include<stdio.h>
#include<conio.h>
main( )
{
 float   bs, gs, da, hra ;

 printf ( "Enter basic salary " ) ;
 scanf ( "%f", &bs ) ;

 if ( bs < 1500 )
 {
  hra = bs * 10 / 100 ;
  da = bs * 90 / 100 ;
 }
 else
 {
  hra = 500 ;
  da = bs * 98 / 100 ;
 }

 gs = bs + hra + da ;
 printf ( "gross salary = Rs. %f", gs ) ;
 getch();
} 

Calculation of bonus


/* Calculation of bonus */
#include<stdio.h>
#include<conio.h>
main( )
{
 int   bonus, cy, yoj, yr_of_ser ;

 printf ( "Enter current year and year of joining " ) ;
 scanf ( "%d %d", &cy, &yoj ) ;

 yr_of_ser = cy - yoj ;

 if ( yr_of_ser > 3 )
 {
  bonus = 2500 ;
  printf ( "Bonus = Rs. %d", bonus ) ;
 }
}

WAP to Demonstration of if statement


/*WAP to Demonstration of if statement */
#include<stdio.h>
#include<conio.h>
main( )
{
 int   num ;

 printf ( "Enter a number less than 10 " ) ;
 scanf ( "%d", &num ) ;

 if ( num <= 10 )
  printf ( "Entered number is less than 10=%d",num) ;
 getch();
}

WAP to use Objects are passed by reference


/*WAP to use Objects are passed by reference*/
class Test {
int a, b;
Test(int i, int j) {
a = i;
b = j;
}
// pass an object
void meth(Test o) {
o.a *= 2;
o.b /= 2;
}
}
class CallByRef {
public static void main(String args[]) {
Test ob = new Test(15, 20);
System.out.println("ob.a and ob.b before call: " +
ob.a + " " + ob.b);
ob.meth(ob);
System.out.println("ob.a and ob.b after call: " +
ob.a + " " + ob.b);
}
}

Sunday, September 12, 2010

WAP to Calculation of simple interest


/*WAP to Calculation of simple interest */
#include<stdio.h>
#include<conio.h>
main( )
{
 int   p, n ;
 float   r, si ; 

 p = 1000 ;
 n = 3 ;
 r = 4.5 ;

 /* formula for simple interest */
 si = p * n * r / 100 ;  

 printf ( "%f" , si ) ;
} 

Addition of two equations-FUN


Q: Addition of two equations.
equ1- Study=Don't Fail
equ2- Don't Study=Fail
Ans: Study+Don't Study = Fail+Don't Fail
=>Study(1+Don't)=Fail(1+Don't)
=>Study=Fail

WAP to Convert Decimal to Binary


/*Convert Decimal to Binary*/
#include<stdio.h>
#include<conio.h>
void main()
{
 clrscr();
 int a,b,x,y,i[5],j,r;
 printf("Enter  no.");
 scanf("%d",&a);
 x=a%2;
 y=a/2;
 b=(y*2)+(x);
 for(j=0;b!=0;b/=2)
 {
  i[j]=b%2;
  j++;
 }
 for(r=j-1;r>=0;r--)
 {
  printf("%d",i[r]);
 }
 getch();
}

Saturday, September 11, 2010

Write a program to convert Octal to Binary


/*Write a program to convert Octal to Binary*/
#include<stdio.h>

#include<conio.h>

void main()

{

 clrscr();

 int a,b;

 printf("Enter 2 digit octal no.");

 scanf("%d",&a);

 int x,y;

 x=a%10;

 y=a/10;

 b=(y*8)+(x);//changing no. to decimal

 int i[5];

 for(int j=0;b!=0;b/=2)

 {



  i[j]=b%2;

  j++;

 }

 for(int r=j-1;r>=0;r--)

 {

  printf("%d",i[r]);
 }
 getch();
}

Thursday, September 9, 2010

WAP to print star


/*WAP to print star*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,j;
clrscr();   //clear screen

for(i='A';i<='E';i++) //loop starts from 1 for row
{
for(j='A';j<=i;j++)   // loop executes i times for colom
printf("%c",j);   // print j
printf("\n");    // goto next line
}
getch();
}

Wednesday, September 8, 2010

WAP to use of array


/*WAP to use of array*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,marks[5]={50,40,60,70,80,};
clrscr();
for(i=0;i<=5;i++)
{
printf("\n%d",marks[i]);
}
getch();
}

Tuesday, September 7, 2010

WAP to sum 1d-array


/*WAP to sum 1d-array*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3],b[3],c[3],i;
clrscr();
printf("enter 1 array elements no.s");
for(i=0;i<3;i++)
{
scanf("%d",&a[i]);
}
printf("enter 2 array elements no.s");
for(i=0;i<3;i++)
{
scanf("%d",&b[i]);
}
for(i=0;i<3;i++)
{
printf("sum of 2 array");
for(i=0;i<3;i++)
{
c[i]=a[i]+b[i];
printf("\n%d",c[i]);
}
}
getch();
}

Friday, September 3, 2010

WAP of display Alphabet


/*WAP of display Alphabet*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,j;
clrscr();   //clear screen

for(i='A';i<='E';i++) //loop starts from 1 for row
{
for(j='A';j<=i;j++)   // loop executes i times for colom
printf("%c",i);   // print j
printf("\n");    // goto next line
}
getch();
}

Tuesday, August 31, 2010

WAP to use of sizeof


/*use of sizeof*/

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
char a;
int b;
float c;
double d;
a=sizeof(char);
b=sizeof(int);
c=sizeof(float);
d=sizeof(double);

printf("\nsize of char=%d\n",a);
printf("\nsize of integer=%d\n",b);
printf("\nsizeof float=%f\n",c);
printf("\nsize of d float=%f\n",d);
getch();
}

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