Skip to main content


Showing posts from October, 2010

PyTorch Code for Simple Neural Networks for MNIST Dataset

Installing Omnet in Ubuntu 10.10

To install Omnet on Ubuntu 10.10, the following are necessary Java (jdk) Gcc Compiler / G++ Compiler zlibraries and other components Here are the instructions Download Omnet from   (the latest edition is 4.1) Download the omnet-xxx.tgz file (its for linux) Open the terminal, untar it to any folder in linux (in my case it is /home/pradeepkumar/) using the following command tar zxvf omnet-xxx.tgz go to the folder by this command cd omnet-xx/ (the above command creates a folder and untar all the contents into it) execute the command ./configure you may get some errors like unavailability of packages and dependencies, execute the following command to download and install all the packages for running the following command, your machine has to be connected to the internet…. sudo apt-get install bison flex byacc zlib1g-dev tcl tk tcl8.4 tk8.4 tcl8.4-dev tk8.4-dev build-essentials libxmu-dev once all

checking system version (for dynamic loading)...

If you encounter the following error,  checking system version (for dynamic loading)... ./configure: 1: Syntax error: Unterminated quoted string then do the following, Open the following files under ns-allinone-2.xx/ tcl: file tcl8.x.x/unix/tcl.m4 tk: file tk8.x.x/unix/tcl.m4 otcl: file otcl-1.x/ In all the above files, you can find the following line system=MP-RAS-`awk ' { print $3 } '/etc/.relid'` and change the above line to (just remove the last but one single quote, remember that ‘ is different from ` you need to remove only ‘ and not `) system=MP-RAS-`awk ' { print $3 } '/etc/.relid`

C Program–Passing an entire array to a function

/* This program is to pass the entire array to a function */ #include <stdio.h> #include <conio.h> int maximum(int[],int); //function prototype, 1st parameter is array and the second is integer int main() {     int a[100],i,n,max=0;     printf("Enter the numbers");      scanf("%d",&n); //get the index number     for(i=0;i<n;i++) //get the array elements     {     scanf("%d",&a[i]);     }     max=maximum(a,n); //function call     printf("Maximum number is %d",max);     getch();     return 0; } int maximum(int b[],int a) //function implementation {     int i,max=b[0];     for(i=0;i<a;i++)     if(b[i]>max)     max=b[i];     return max; } In the function call ie max=maximum(a,n) where a is the array and n is the number of array elements the above line can be written as max

C Program–Arrays with Functions (passing Array elements to function)

/* Program to demonstrate arrays with function in which the array elements are passed as function parameters */ #include <stdio.h> #include <conio.h> void display(int); //function prototype int main() {     int a[10],i;     for(i=0;i<10;i++) //getting the array elements     {     scanf("%d",&a[i]);     }     for(i=0;i<10;i++)         display(a[i]); //call the function inside the loop, this function called for 10 times     getch();     return 0; } void display(int a) //function implementation to print the elements, here the parameter is an integer only(means we are passing the array elements) {      printf("%d",a); }

Arrays in C

Arrays in C programming starts with memory addresses. Yes the compiler handles arrays as memory addresses. Similar elements group together with a single name is called array the indexing always starts with 0 and ends at n-1 (if the size of the array is n) Array elements stores in consecutive memory location. The array elements usually stores in consecutive memory location. For example, int a[10];  //Array with size 10 the above example is an integer array with size 10 or this array can hold 10 variables. The elements starts from a[0], a[1], a[2]…..a[9], so totally there are 10 elements. Array elements values memory address location a[0] 32 600AH  (This address is called as the base address) a[1] 34 600EH a[2] 23 6012H a[3] 35 6016H a[4] 45 601AH

Functions in C

Almost all the programming languages uses functions. Functions are the entities which are grouping a set of statements which do a specific job or set of jobs. Example: sum of integers, sum of float number, complex number addition. All the above three can be implemented as a single function or three separate functions. When someone wants to use that, a function can be simply called. So function implementation happens as Function prototype or Function declaration Function definition or function implementation Function call Function prototype It is necessary to specify the name of the function, the parameters and the return type to the compiler that the function is being defined in this program. The prototype ends with a semicolon syntax: int sum(int, int); //function prototype Function Definition This is the actual function definition which shows the function implementation. for the above syntax here is the function int sum(int a, int

C Program 4–To check whether a given number is prime or not

A prime number can be divided by 1 and itself, there are no other divisors, Examples are : 2 3, 5, 7, 11, ….. To find out whether a given number is prime or not, here is the logic 1. Get the number 2. divide the given number from 2 to n-1 (Example if 6 is the number divided by 2,3,4,5 will get the remainder respectively 0,0,2,3) 3. increment a counter to 1 if the remainder is 0 4. if there counter variable is 0, then the given number is prime (because we didn’t get any remainder) else non prime Here is the program #include <stdio.h> #include <conio.h> int main() {     int a,i,count=0;     printf("enter a"); //Let the given number is a     scanf("%d",&a); //get the number     for(i=2;i<a;i++) //divide the number a from 2 to a-1     {     if(a%i==0)      count++; //increment a counter if the divisibility is 0     }     if(count !=0) //if the counter is not zero, then prime

Ubuntu 10.10

Here is the next version ubuntu 10.10, its released on 10-10-2010. Features Browse the web through firefox, chromium (download from ubuntu software center) as usual you can use openoffice for creating office documents. Email and chat through Empathy IM and Evolution (skype and thunderbird also supporting) Social from the start (like facebook, twitter, Music streaming with ubuntu one and rhythm box music player Photo magic (shotwell, flickr, GIMP) Make, play and edit video with Pitvi video editor and more

C Program 3 – To check whether a number is Armstrong Number

The armstrong number is of the form 153= 1 3 + 5 3 + 3 3 The input is : 153 or any other number output: The number is armstrong or not. Processing: take 153 as an example, remove 3, 5 and 1 in the reverse order (using % operator) and take the power of 3 and add to the sum variable. if the total sum and the original number, both are same, then that is the arm strong number. if else, the number is not an armstrong number #include <stdio.h> #include <conio.h> int main() {     int original_num, check, temp, sum=0;     printf("Enter the number to check for armstrong number");     scanf("%d", &original_num); // Get the original number     temp=original_num;     while(original_num>0) //run the loop till the number becomes 0     {      check=original_num%10;  //remove the last digit using modulo operator      sum=sum+check*check*check; //the last digit is taken powe