## 9.30.2012

### Star Structure

Q. Write a c program to print the following star structure:

*********
*******
*****
***
*
***
*****
*******
*********

Ans.
/*c program for print the star structure*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,n,r,c,sp;
printf("Enter number of rows: ");
scanf("%d", &num);
printf("\n");
n=num;
for(r=1; r<=num; r++)
{
for(sp=1; sp<=r; sp++)
printf(" ");
for(c=1; c<=n; c++)
printf("*");
for(c=num-r; c>=1; c--)
printf("*");
n--;
printf("\n");
}
for(r=2; r<=num; r++)
{
for(sp=num-r+1; sp>=1; sp--)
printf(" ");
for(c=1; c<=r; c++)
printf("*");
for(c=r-1; c>=1; c--)
printf("*");
printf("\n");
}
return 0;
}

The output of above program would be:

 Screen shot for specific star structure C program

## 9.25.2012

### Star triple pyramid

Q. Write a C program to print the following star triangle:

*
* *
*
* *
* * *
*
* *
* * *
* * * *

Ans.

 Screen shot of solutions for star pyramid breaks in module sub programs

/*c program for star pyramid or star triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int r,c,sp,n=4;
for(r=1;r<=2; r++)
{
for(sp=1; sp<=n; sp++)
printf(" ");
for(c=1; c<=r; c++)
{
printf("*");
printf(" ");
}
printf("\n");
n=n-1;
}

for(r=1;r<=3; r++)
{
for(sp=0; sp<=n+1; sp++)
printf(" ");
for(c=1; c<=r; c++)
{
printf("*");
printf(" ");
}
printf("\n");
n=n-1;
}

for(r=1;r<=4; r++)
{
for(sp=0; sp<=n+4; sp++)
printf(" ");
for(c=1; c<=r; c++)
{
printf("*");
printf(" ");
}
printf("\n");
n=n-1;
}
getch();
return 0;
}

The output of above program would be:

 Screen shot for star pyramid C program

## 9.17.2012

### Number Pyramid

Q. Write a C program for print the following number triangle:
or
Q. Write a C program for display the following number pyramid:

5
45
345
2345
12345

Ans.

/*c program for number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int r,num,n,i;
printf("Enter number of rows : ");
scanf("%d", &num);
n = num;
for(r=1; r<=num; r++,n--)
{
for(i=n; i<=num; i++)
printf("%d", i);
printf("\n");
}
getch();
return 0;
}

The output of above program would be:

 Screen shot for number pyramid C program

### Number Pyramid

Q. Write a C program for print the following number triangle:
or
Q. Write a C program for display the following number pyramid:

5
454
34543
23454321
123454321

Ans.

/*c program for number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int r,num,n,i,j;
printf("Enter number of rows : ");
scanf("%d", &num);
n = num;
for(r=1; r<=num; r++,n--)
{
for(i=n; i<=num; i++)
printf("%d", i);
for(j=num-1; j>=n; j--)
printf("%d", j);
printf("\n");
}
getch();
return 0;
}

The output of above program would be:

 Screen shot for number triangle C program

### Number Triangle

Q. Write a C program for print the following number triangle:
or
Q. Write a C program for display the following number pyramid:

9
898
78987
6789876

Ans.

/*c program for number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int r,num=9,n,i,j;
n = num;
for(r=1; r<=4; r++,n--)
{
for(i=n; i<=num; i++)
printf("%d", i);
for(j=num-1; j>=n; j--)
printf("%d", j);
printf("\n");
}
getch();
return 0;
}

The output of above program would be:

 Screen shot for specific number pyramid C program

## 9.14.2012

### Short-Circuit operators

C language has two types short-circuit operators:

1. Logical AND operator  &&
2. Logical OR operator  ||
What is meaning of short-circuit

In C language, the meaning of short-circuit is that if there are any expression, then output of expression must be determined by the left side operand, and right side operand never be executed.
Here two case occurred,:
what would be output if left side operand is true?
what would be output if left side operand is false?

keep in mind: 0 or any negative value is always false.
1 or any non-zero value is always true.

Let's understand short-circuit operators by example:

x && y

hear, if left side operand x is false then overall expression to be false, and the right side operand y never evaluated.
If left side operand x is true then result of expression depend upon  right side  operand y and in this case  right side  operand will be evaluated.

m || n

here, if left side operand m is true then overall expression to be true, and right side operand n not to be evaluated.

/*c program for logical OR short-circuit operator example*/
#include<stdio.h>
int main()
{
int x, y , z;
x = y = z = 1;

++x || ++y;

printf("\n x=%d\t y=%d\t z=%d \n", x,y,z );
getch();
return 0;
}

The output of above program would be:

x=2  y=1  z=1
explanations: In above program logical OR short-circuit operator, in expression left hand side operand x is true so its increase ++x i.e. x=2. And right side operand y not to be evaluated.

-------------------------------------------------------------------

/*c program for exercise of logical OR short-circuit operator operators*/

#include<stdio.h>
int main()
{
int x, y , z;

x = y = z = 0;

++x || ++y;

printf("\n x=%d\t y=%d\t z=%d \n", x,y,z );
getch();
return 0;
}

The output of above program would be:

x=1  y=0  z=0
explanations: In above program logical OR short-circuit operator, in expression left hand side operand x is false so right side operand y not to be evaluated.

-------------------------------------------------------------------

/*c program for exercise of logical AND short-circuit operators example*/

#include<stdio.h>
int main()
{
int x, y , z;

x = y = z = 1;

++x && ++y;

printf("\n x=%d\t y=%d\t z=%d \n",x,y,z );
getch();
return 0;
}

The output of above program would be:

x=2  y=2  z=1
explanations: In above program logical AND short-circuit operator, in expression left hand side operand x is true(++x) so right side operand y also evaluated(++y).

-------------------------------------------------------------------

/*c program for logical AND, logical OR short-circuit operators example*/

#include<stdio.h>
int main()
{
int x, y , z, r;

x = y = z = 1;
r = ++x || ++y && ++z;
printf("\nr=%d", r);
printf("\nx=%d y=%d z=%d\n", x,y,z);

x = y = z = 1;
r = ++x && ++y || ++z;
printf("\nr=%d", r);
printf("\nx=%d y=%d z=%d\n", x,y,z);

x = y = z = 1;
r = ++x || ++y || ++z;
printf("\nr=%d", r);
printf("\nx=%d y=%d z=%d\n", x,y,z);

x = y = z = 1;
r = ++x && ++y && ++z;
printf("\nr=%d", r);
printf("\nx=%d y=%d z=%d\n", x,y,z);

x = y = z = 1;
r = ++x || ++y && ++z;
printf("\nr=%d", r);
printf("\nx=%d y=%d z=%d\n", x,y,z);

x = y = z = -1;
r = ++x || ++y && ++z;
printf("\nr=%d", r);
printf("\nx=%d y=%d z=%d\n", x,y,z);

x = y = z = -1;
r = ++x && ++y  ||  ++z;
printf("\nr=%d", r);
printf("\nx=%d y=%d z=%d\n", x,y,z);

x = y = z = -1;
r = ++x  ||  ++y  ||  ++z;
printf("\nr=%d", r);
printf("\nx=%d y=%d z=%d\n", x,y,z);

x = y = z = -1;
r = ++x  &&  ++y  &&  ++z;
printf("\nr=%d", r);
printf("\nx=%d y=%d z=%d\n", x,y,z);

x = y = z = -1;
r = ++x || ++y  &&  ++z;
printf("\nr=%d", r);
printf("\nx=%d y=%d z=%d\n", x,y,z);

getch();
return 0;
}

The output of above program would be:

 Screen shot for logical AND, logical OR short circuit operator C program

## 9.12.2012

### Heap Sorting method and algorithm

In heap sorting process:

First of all organizing the whole data to be sorted as a binary tree i.e. heap. And after that impletment heap sorting.

Step 1: (How to data organizing as binary tree?)

Remember only 2 rule:

Rule:1.

The parent node must be greater then child node.
If parent node is not greater then to child node not replace it with parent node. And if binary tree is large then, if relaceing child node(now its parent node) is greater then to great-parent node then its also is replace the great-parent node.

Rule:2.

New element always insert in left side and after right side of parent node.
If left side of parent element has already element then new element would be insert in right side. And if right side of parent node has already element then new element will be insert in left side.

Step 2: (How to perform heap sorting:)

## 9.11.2012

### Pointer Extend Example

Can a pointer variable, itself might be another pointer?
Yes, this pointer would be contains another pointer's address.

The following example/program should should make this point clear:

/*c program for pointer extend example*/

#include<stdio.h>
int main()
{
int x=5;
int *y, **z;

y = &x;
z = &y;

printf("\nAddress of x = %u", &x);
printf("\nAddress of x = %u", y);
printf("\nAddress of x = %u", *z);
printf("\nAddress of y = %u", &y);
printf("\nAddress of y = %u", z);
printf("\nAddress of z = %u", &z);
printf("\nValue of y = %u", y);
printf("\nValue of z = %u", z);
printf("\nValue of x = %u", x);
printf("\nValue of x = %u", *(&x));
printf("\nValue of x = %u", *y);
printf("\nValue of x = %u", **z);

getch();
return 0;
}

The output of the above program would be:

 Screen shot for pointer extend example C program

Read above program carefully, the addresses that get output might be something different.
The relationship between x, y and z can be easily summarized as:

Name ----------------       x                    y               z

Value -------------------    5               2293620       2293616

What is the meaning of int x, *y, **z;

Here, x is an ordinary int variable,
y is a pointer to an int i.e. integer pointer,
z is pointer to an integer pointer.

We can extend the above program still further by creating a pointer to a pointer to an integer pointer i.e.  ***n
There is no limit on how far can we go on extending this definition. Possibly, till the point we can comprehend it. And that point of comprehension is usually a pointer to a pointer.

Related programs:

## 9.10.2012

### Function Key Shortcuts

There are 12 function keys in the keyboard. These function keys meaning, combine with other key shortcuts are as following:

F1
Display the Help.

F2
Rename the selected item.

F3
Search for file or folder

F4
Display the address bar list in Windows Explorer

F5
Refresh the active window

F6
Go to the address bar in browser

F7
spell and grammar check in a document in MS programs.

F8
When system is going to start, and if you press F8 then, it will open in safe mode i.e. access Windows in safe mode

F9
Normally function key F9 not defined any work in Windows. But its can be perform task such as controlling BIOS setup programs, switching display unit etc.

F10
Activate the menu bar in the active program

F11
Go to full Screen in browser

F12
Dock/Undock into Separate Window

Alt + F4
Exit the active window

Ctrl + F4
Close the active window

Shift + F10

Related programs:

### Dialog Box Shortcuts

The below are the shortcuts which are used geneally in as form, save, open etc.

Enter
Perform the equivalent to hitting the OK button

Space
Change the state of Check box or radio button.

Tab
Move forward through options

Shfit + Tab
Move back through options

Ctrl + Tab
Move forward through options

Ctrl + Shift + Tab
Move back through tabs

Arrow Keys
Select a button if the active option is a group of option buttons

Backspace
Open a folder one level up if a folder is selected in the Save As open dialog box

Related programs:

### Windows Key Board Shortcuts

The most used Windows keyboard shortcuts as following:

Windows
Open or close the start menu

Windows + PAUSE
Display the System Properties dialog box

Windows + D
Display the desktop

Windows + M
Minimise all windows

Windows + Shift + M
Restore minimised windows to the desktop

Windows + E
Open My Computer

Windows + F
Search for a file or folder

Windows + L
Lock your computer or Switch users

Windows + R
Open the Run dialog box

Windows +  T
Cycle through program on the taskbar

Windows + Tab
Switch program in 3-D ways

Windows + SpaceBar
Brings all gadgets to the front and select Windows Sidebar

Windows + G

Related programs:

### Windows Keyboard Shortcuts

There are many people who want to work faster with Windows. If you know well about key board shortcuts then it will save your time and of course, more easily. We are using Windows XP as reference.

Most used general keyboard shortcuts:

ctrl + C
Copy the selected item or text

ctrl + V
Copy the selected item or text

ctrl + X
Cut and Copy the selected item or text

ctrl + Z
Undo the last work

ctrl + Y
Redo the last work

delete
Delete the selected item and move it to the Recycle Bin

Shift + Delete
Delete the selected item parmantly from system

Ctrl + Right Arrow
Move the cursor to the beginning of the next word

Ctrl + Left Arrow
Move the cursor to the beginning of the previous word

Ctrl + Down Arrow
Move the cursor to the beginning of the next paragraph

Ctrl + Up Arrow
Move the cursor to the beginning of the previous paragraph

Ctrl + Shift + an arrow key
Select a block of text

Shift + an arrow key
Select particular text

Ctrl + any arrow key + SpaceBar
Select multiple individual items

Ctrl + A
Select all items in a document or window

Alt + Enter
Display the properties of the selected item

Alt + Tab
Switch between open program or items

Alt + Esc
Cycle through items in the order in which they were opened

Ctrl + Esc  or [Windows]

Alt + Hot Key
Hot key is a underlined key, when press the underlined word with Alt, its perform the related work.

Esc

Ctrl + Shift + Esc or Ctrl + Alt + Delete

Related programs:

## 9.09.2012

### Make Own Windows Run Command

Can i create my own Windows Run Command?
or
How I create my own Windows Run Command?

Yes, You can create your own Windows Run Command. It is very simple. To make your own  Windows Run Command, follow the following steps:

step 1:

Create a Shortcut at desktop for your program, which you want to make "Run Command".

step 2:

Now re-name of shortcut and give your run command name.
For example, we replace the shortcut name to "expertofxp".

step 3: Move this shortcut to c:\Windows

step 4: Finish. Congratulations you done it.

Now check it now:

go to start > Run
and type the name of shortcut, in our case, we type: expertofxp
click OK

and the related program will be open.

Related programs:

### Run Command Shortcuts

If you want to work faster at computer system, then it is best practise to use keyboard shortcuts.

If you want to start a new application / utilities, then you navigate hundred windows and dialog boxes. Or rather then you can do same job through "Run Command".

How to reach run command?

1. Start > Run
2. press ( [Windows] + [R] )
The keyboard shortcuts for run command in Windows XP:

Mostly use run command shortcuts as:

Calculator -------------------------------  calc
Character map --------------------------  charmap
Clipboard --------------------------------  clipbrd
Command Prompt ----------------------  cmd or command
Computer Management ---------------  compmgmt.msc
Control panel --------------------------  control
Display Properties --------------------  desk.cpl or control desktop
Date and Time properties ----------  timedate.cpl
Fonts -----------------------------------  control fonts
Game Controllers ---------------------  joy.cpl
Internet Explorer ---------------------  iexplore
Keyboard Properties -----------------  control keyboard
Microsoft Word -----------------------  winword
Microsoft Excel -----------------------  excel
Microsoft PowerPoint ----------------  powerpnt
Microsoft Paint -----------------------  mspaint or pbrush
Mouse Properties --------------------  main.cpl
On Screen Keyboard ----------------  osk
Outlook Express --------------------  msimn
Printers and Faxes --------------------  control printers
Regional Settings -------------------  intl.cpl
shutdown Windows -------------------  shutdown
Sounds and Audio ---------------------  mmsys.cpl
System Configuration Editor ---------  sysedit
System Configuration Utility ---------  msconfig
System Information -------------------  msinfo32
System Properties ---------------------  sysdm.cpl
Windows Explorer ---------------------  explorer
Windows Firewall ----------------------  firewall.cpl
Windows Magnifier --------------------  magnify
Windows Media Player ----------------  wmplayer
Windows System Security Tool ------  syskey
Windows Version ----------------------  winver

Related programs:

### Number Pyramid

Q. Write a C program to print the following number triangle.
or
Q. Write a C program to display the following number pyramid.

1
222
33333
4444444
555555555

Ans.

/*c program for number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c,k,sp;
printf("Enter number of rows : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(sp=num-r; sp>0; sp--)
printf(" ");
for(c=1; c<=r; c++)
printf("%d", r);
for(k=2; k<=r; k++)
printf("%d", r);
printf("\n");
}
getch();
return 0;
}

/**************Output**************/

 Screen shot for number pyramid C program