October 10, 2013

C program to print the hollow stars square

Here is the code for the C program to print the star formation of a hollow square. The program will input an integer value from the user and print the hollow star formations.
Here is the code.

#include “stdio.h”
int main()
{
int num,i,j;
printf("Please enter a number to print the hollow star formation \n");
scanf("%d", &num);
for(i=0;i<num;i++)
{
for(j=0;j<num;j++)
{
if(i==0 || i==num-1)
{
printf("*");
}
else if(j==0 || j==num-1)
{
printf("*");
}
else
{
printf(" "); // space is printed ..
}
}
printf("\n");
}
return 0;
}


























Here is the sample output.
star

As can be seen in the output above, for the user input, the hollow star square will be formed. The key to understand the logic of the code is as follows.
The outerloop controls the number of  lines and inner loop controls the number of stars.

October 8, 2013

C program to display integers in Ascending without using Loop

This program run sorts and display the integers in ascending order. It finds the largest and smallest integer values respectively.



#include "stdio.h"
#include "conio.h"


int main()



{


    int a=0, b=0, c=0,d=0,e=0, f=0, grade;
    printf("Enter four numbers\n");
   
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&d);
   
    if(a>b && a>c && a>d)
    {
           printf("1st value that you entered is largest\n");
           e=1;
    }
    else if(b>a && b>c && b>d)
    {
           printf("2nd value that you entered is largest\n");
           e=2;
    }
    else if(c>a && c>b && c>d)
    {
           printf("3rd value that you entered is largest\n");   
           e=3;
    }
    else if(d>a && d>b && d>c)
    {
           printf("4th value that you entered is largest\n");
           e=4;
    }

// For finding smallest value

     if(a
    {
           printf("1st value that you entered is smallest\n");
           f=1;
    }
    else if(b
    {
           printf("2nd value that you entered is smallest\n");
           f=2;
    }
    else if(c
    {
           printf("3rd value that you entered is smallest\n");
           f=3;
    }
    else if(d
    {
           printf("4th value that you entered is smallest\n");
           f=4;
    }

//Sorting //

    if(e==1 && f==2)
    {
            if(c
            {
                   printf("Sorted order is \n %d %d %d %d", b,c , d, a);
            }
            else
            {
                printf("Sorted order is \n %d %d %d %d", b,d , c, a);
            }
    }
    else
    if(e==1 && f==3)
    {
            if(b
            {
                   printf("Sorted order is \n %d %d %d %d", c,b , d, a);
            }
            else
            {
                printf("Sorted order is \n %d %d %d %d", c,d , b, a);
            }
    }
    else
    if(e==1 && f==4)
    {
             if(b
            {
                   printf("Sorted order is \n %d %d %d %d", d,b , c, a);
            }
            else
            {
                printf("Sorted order is \n %d %d %d %d", d,c , b, a);
            }
    }
   
    // for e=2
   
        if(e==2 && f==1) // a is smallest, b is largest
    {
            if(c
            {
                   printf("Sorted order is \n %d %d %d %d",a, c , d, b);
            }
            else
            {
                printf("Sorted order is \n %d %d %d %d", a,d , c, b);
            }
    }
    else
    if(e==2 && f==3)// c is smallest
    {
            if(a
            {
                   printf("Sorted order is \n %d %d %d %d", c,a , d, b);
            }
            else
            {
                printf("Sorted order is \n %d %d %d %d", c,d , a, b);
            }
    }
    else
    if(e==2 && f==4)  // d is smallest
    {
             if(a
            {
                   printf("Sorted order is \n %d %d %d %d", d,a , c, b);
            }
            else
            {
                printf("Sorted order is \n %d %d %d %d", d,c , a, b);
            }
    }
   
    // for c is largest i.e.. e=3
            if(e==3 && f==1) // a is smallest, c is largest
    {
            if(b
            {
                   printf("Sorted order is \n %d %d %d %d",a, b , d, c);
            }
            else
            {
                printf("Sorted order is \n %d %d %d %d", a,d , b, c);
            }
    }
    else
    if(e==3 && f==2)// b is smallest
    {
            if(a
            {
                   printf("Sorted order is \n %d %d %d %d", b,a , d, c);
            }
            else
            {
                printf("Sorted order is \n %d %d %d %d", b,d , a, c);
            }
    }
    else
    if(e==3 && f==4)  // d is smallest
    {
             if(a
            {
                   printf("Sorted order is \n %d %d %d %d", d,a , b, c);
            }
            else
            {
                printf("Sorted order is \n %d %d %d %d", d,b , a, c);
            }
    }   
   
       
    // for d is largest i.e.. e=4
   
   
   
            if(e==4 && f==1) // a is smallest
    {
            if(b
            {
                   printf("Sorted order is \n %d %d %d %d",a, b , c, d);
            }
            else
            {
                printf("Sorted order is \n %d %d %d %d", a,c , b, d);
            }
    }
    else
    if(e==4 && f==2)// b is smallest
    {
            if(a
            {
                   printf("Sorted order is \n %d %d %d %d", b,a , c, d);
            }
            else
            {
                printf("Sorted order is \n %d %d %d %d", b,c , a, d);
            }
    }
    else
    if(e==4 && f==3)  // d is smallest
    {
             if(a
            {
                   printf("Sorted order is \n %d %d %d %d", d,a , b, d);
            }
            else
            {
                printf("Sorted order is \n %d %d %d %d", d,b , a, d);
            }
    }       

    getch();
    return 0;
   
   
}


Here is the output.


 

September 25, 2013

Ubuntu Installation using Windows Installer

There is an absolute easy way to install  ubuntu. Let us see step by step procedure to install ubuntu by using ubuntu windows installer.
First download the windows installer by writing following in google and open the first link.
1
Now, click on the Get the installer button.

September 9, 2013

C Program Phases Writing And Executing A Program

System Software
The system software controls the computer. It communicates with computer’s hardware (key board, mouse, modem, sound card etc) and controls different aspects of operations. Sub categories of system software are:
  • Operating system
  • Device drivers
  • Utilities
Operating system

An operating system (sometimes abbreviated as "OS") is the program that manages all the other programs in a computer. It is a integrated collection of routines that service the sequencing and processing of programs by a computer. Note: An operating system may provide many services, such as resource allocation, scheduling, input/output control, and data management.

Device drivers

The device driver software is used to communicate between the devices and the computer. We have monitor, keyboard and mouse attached to almost all PC’s; if we look at the properties of these devices we will see that the operating system has installed special software to control these devices. This piece of software is called device driver software. When we attach a new device with the computer, we need software to communicate with this device. These kinds of software are known as device drivers e.g. CD Rom driver, Sound Card driver and Modem driver. Normally manufacturer of the device provide the device driver software with the device. For scanners to work properly with the computers we install the device driver of the scanner. Nowadays if you have seen a scanner, it comes with TWAIN Drivers. TWAIN stands for Technology Without An Interesting Name.

September 4, 2013

Installation of Dev C++


Here is the step by step procedure for the installation of Dev C++
First, download the Dev C++ from the following link.
http://sourceforge.net/projects/orwelldevcpp/files/latest/download

Then after download execute the setup.  The screenshots are of different versions.

1

Select Language.

 2
Click I agree.

September 3, 2013

Introduction to Programming

Definition

"A program is a precise sequence of steps to solve a particular problem.”It means that when we say that we have a program, it actually means that we know about a complete set activities to be performed in a particular order. The purpose of these activities is to solve a given problem. Alan Perlis, a professor at Yale University, says:"It goes against the grain of modern education to teach children to program. What fun is there in making plans, acquiring discipline in organizing thoughts, devoting attention to detail and learning to be self-critical? ". It is a sarcastic statement about modern education, and it means that the modern education is not developing critical skills like planning, organizing and paying attention to detail. Practically, in our day to day lives we are constantly planning, organizing and paying attention to fine details (if we want our plans to succeed). And it is also fun to do these activities. For example, for a picnic trip we plan where to go, what to wear, what to take for lunch, organize travel details and have a good time while doing so.

May 27, 2013

Xgraph in NS2

 

One part of the ns-allinone package is 'xgraph', a plotting program which can be used to create graphic representations of simulation results. In this section, I will show you a simple way how you can create output files in your Tcl scripts which can be used as data sets for xgraph. On the way there, I will also show you how to use traffic generators.
A note: The technique I present here is one of many possible ways to create output files suitable for xgraph. If you think there is a technique which is superior in terms of understandablity (which is what I aim for in this tutorial), please let me know.


First of all, we create the following topology:
 
Nam snap shot
 
The following piece of code should look familiar to you by now if you read the first sections of this tutorial.



set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]

$ns duplex-link $n0 $n3 1Mb 100ms DropTail
$ns duplex-link $n1 $n3 1Mb 100ms DropTail
$ns duplex-link $n2 $n3 1Mb 100ms DropTail
$ns duplex-link $n3 $n4 1Mb 100ms DropTail


C program to Read From a File

#include <stdio.h> #include <stdlib.h> void main() {     FILE *fptr;     char filename[15];     char ch;   ...