Friday, September 23

placement

If you are preparing for a campus recruitment for an IT company it is important to be clear with the basics of these languages well. There would be questions around this, especially if you have mentioned them in your Resume. The information below would be useful for you. While it is a bit in detail, at least knowing clearly a portion of this will be handy. Please do not try to over learn and create an impression to the interviewer that you are trying to be extra smart.  I have compiled this for you and hope it will be useful. Be clear with the basics of Object Orientation like Encapsulation, Polymorphism etc. Java and C The main difference between Java and C are speed, portability, and object-orientation. Java was created for the purpose of making a language that could be implemented...

Wednesday, September 21

Check a Number in parent process and pass result to Child Process

#include<stdio.h> #include<unistd.h> main() { int fd[2],f,i,num,flag=1;pipe(fd); f=fork(); if(f>0) { printf("PARENT PROCESS.."); printf("\nEnter a number : "); scanf("%d",&num); if(num==1)flag=0;for(i=2;i<=(num/2);i++) if(num%i==0) { flag=0; break; } close(fd[0]); write(fd[1],&flag,sizeof(flag)); } else if (f==0) { printf("\n\nCHILD PROCESS.");close(fd[1]); read(fd[0],&flag,sizeof(flag)); if(flag==1)printf(" \n\tIt is a prime number..\n"); else printf("\n\t It is not a prime number..\n"); } ...

Monday, September 19

Code to Access GPS in Android Phones

GET !!! SET !! GO..!!!!!!!! Location Based Services (LBS) have become very popular in past few years after the advent of GPS enabled smartphone devices . In this post, we shall see how a LBS application for Android works. Simply speaking map navigation is possible in  following ways: Using the GPS device in built in mobile-    Easier and precise. Using the ID of the Cell that the user is currently served by How to code? We can give dummy values as GPS co-ordiantes for a location(i.e., Longitude and Latitude) .Another way to emulate location is to including .gpx files. Although it is not...

Saturday, September 17

Print a string without using any semicolon

Write a program to print a  string without using any semicolon on the program: #include<stdio.h> main() {       if(printf("Hello.."))       {       } } I want to know how this program can modified to print any string accepted through Keyboard..!! If anyone know, feel free to comment it here..!!  :):)...

Letter Pattern

Write a program to print the following          A        B B       CC CC    DDD DDD #include<stdio.h> main() {       int i,j,n;       printf("Enter Limit..  :  ");       scanf("%d",&n);       for(i=0;i<n;i++)       {       for(j=0;j<(n-i);j++)       printf(" ");       if(i==0)putchar(65);       for(j=0;j<i;j++)putchar(65+i);      printf(" ");         for(j=0;j<i;j++)putchar(65+i);        ...

C program to print a Number pattern

Write a program to print the following pattern: 0 1 1 2 3 5 8 13 21 34 Hi buddy, Jst analyse the no.s in order, 0,1,1,2,3,5,8,13,21,34.... Yess!!!! this is a Fibonacci series. 0+1=1 1+1=2 1+2=3 2+3=5... and so on Next requirement is to generate pattern. First line has 1 element, second line has 2 elements and so on. And total number of elements in whole pattern will be N*(N+1)/2 , if there are N number of lines. #include<stdio.h> main() {       int n,i,j,k=0;       int a[20];       printf("Enter the lmit..:   ");       scanf("%d",&n);       a[0]=0;       a[1]=1;      ...

C program to Print a number table

Write a program to display the following format: Nosum 11 23 36 410 515 Logic: First column contains natural numbers serially.. second column contains  ( Current first column element+ previous second column element) 2+1=3 3+3=6 4+6=10 5+10=15 #include<stdio.h> main() {       int j=0,z,i,n;       printf("Enter the Limit...  :  ");       scanf("%d",&n);       printf("\n----------------\n printf("no\tsum"); printf("\n------------------\n");             for(i=1;i<=n;i++)       {       printf("\n%d",i);       j+=i;      ...

Reverse words in a string using Recursion

Write a program to perform the following to any input string:              Input : Structure is a derived datatype       output: erutcurtS si a devired epytatad My Code: #include<stdio.h> #include<string.h> int main() {     char line[20],word[10];     int i,j=0,len;     printf("Entera string :  ");     gets(line);     len=strlen(line);     for(i=0;i<len;i++)     {     while(line[i]!=' '&&i<len)     word[j++]=line[i++];     for(j--;j>=0;j--)     printf("%c",word[j]);     printf(" ");    ...

C program to find Size of a structure without using sizeof() operator

Write a program to find the size of following structure without using size of operator struct ABC  {  int a;  float b;  char c;  }; Hai Viewer, confused?? Hmm.. calculating the size of a datatype without using sizeof() operator seems to be weird. But pointers will help you to solve this problem.  First u have to initialize a null pointer on intended datatype .You know that in 'structure ' separate memory will be allocated to each element. So, on incrementing that pointer variable, the value of that pointer will be incremented by size of that structure . That is our Goal..!!!! :) Since we have initialized pointer with 0 we simply need to print the current pointer value..!! solution #include<stdio.h> struct  ABC {     int...

C program to Print a Non-Fibonacci series

Write a C program to generate non-fibonacci series to given Limit: #include<stdio.h> #include<conio.h> main() {  int n,a,b,c,d,x;  a=0;  b=1;  c=0;  printf("Enter the upper range of the series:");  scanf("%d",&n);  while(c<=n)  {   c=a+b;   a=b;   b=c;   d=a+b;   for(x=c+1;x<d;x++)   {    if(x<=n)     printf("%d",x);    else     break;   }  }  getch(); } I hope this code was useful for u!! Have a better program for ths prblm?? Feel free to comment it here..!!  :):)...

C program to Reverse a string using recursion

Write a program to reverse any string using recursion (Maximum 15 steps) Eg: Input   :  Bjarne Stroustrup developed C++      Output  : ++C depoleved purtsuortS enrajB This is one of the common question asked in technical contests and interviews.!! it checks ur knowledge about recursion and string. We recursively calls itself until encountering endl character. This fragment plays the vital role:  { if (current character != endl) process( next caharacter); print(current character);  } My code: #include<stdio.h> char line[20]; void print(int i) {     ...

Coding Contest- Matrix multiplication

PROBLEM : Write a program to multiply two 3 x 3 matrices where resulting matrix should produce If cell element is even '0' If cell element is odd '1' eg: If resulting matrix of multiplication is My code: #include<stdio.h> main() {       int a[3][3],b[3][3],c[3][3],d[3][3];       int i,j,k;       printf("Enter First matrix:...\n");       for(i=0;i<3;i++)       for(j=0;j<3;j++)       scanf("%d",&a[i][j]);        printf("Enter Second matrix:...\n");      ...

Friday, September 9

LEX Program to identify Keywords and convert it into uppercase

Guys, apply simple logic. Detect all keywords( This program deal with a small number of keywods for sake of simplicity). On detecting any keyword in C, convert it into uppercasr letter using the funtion 'toupper' . Game over!! %{#include<stdio.h> int i; %}keyword main|int|scanf|printf|if|else %% {keyword} {  for(i=0;i<yyleng;i++)  printf("%c",toupper(yytext[i]));    } %% main() { yyin=fopen("num.c","r"); yylex(); } int yywrap() { return 1; } OutputLet num.c contains following program fragment. main() { int num; scanf("%d",&num); if(num%2)printf("Odd"); else printf("Even") } The output will be, MAIN() { INT num; SCANF("%d",&num); IF(num%2)PRINTF("Odd"); ELSE...

LEX Program to eliminate all whitespaces

Hi Guys, This lex program is aimed to eliminate all whitespaces from an input file. As u think, this is not at all a difficult job. We have to simply detect single blank ' ' or tab '\t' or a newline '\n' and delete them in output. That's all..!!!! %{ #include<stdio.h> %} %% [\n\t ' '] {}; %% main() { yyin=fopen("myfile.txt","r"); yylex(); } int yywrap() { return 1; } ____________________________________________________________________ Look @ the example: Basic datatypes in C are: int   char  float   double output will be BasicdatatypesinCare:intcharfloatdouble ...

LEX Program to delete all comments

No Comments  :) This lex program is intended to eliminate comments from a C program. This task is simple since in a C program, comments will be associated only with '//' or '/*...*/ only. So our aim is to detect the occurence of these characters and ignore subsequent comments. %{ #include<stdio.h> %} %% \/\/.* ; \/\*(.*\n)*.*\*\/ ; %% main() { yyin=fopen("mypgm.c","r"); yylex(); } int yywrap() { return 1; } \/\/.* ; eliminates single line coments. i.e., comments of the form ' //comment.. .. .. ;' It simply look on '/'immediately followed by another '/' and ignore that line. \/\*(.*\n)*.*\*\/ ; eliminates multiple...

LEX Program to count the number of lines, words and letters

Howdy guys, Lets have a look on how a Lex programs works using a simple example. This sample programs counts the number of lines, words and characters in a text file.   Lex programming is not rocket science. You have to just apply an eight year old kid's logic. Yes, you read right. Only a school kid's logic. LOGIC Read each character from the text file : Is it a capital letter in English? [A-Z] : increment capital letter count by 1. Is it a small letter in English? [a-z] : increment small letter count by 1 Is it [0-9]? increment digit count by 1. All other characters (like '!', '@','&') are counted as special characters How...

Thursday, September 1

HOW TO INSTALL MATLAB in Windows 7 ???

MatLab is a software by which  you can write nice little programs  and produce pretty pictures and graphs!! It has already inbult functions based on C,C++ and Java etc. We can directly use them or we can develop our own. This language contain programming, graphical used interface, simulink and Animations,coming to electronics ...u have signal procesing, image processing, communications and other related topics directly in the MATLAB.             In this post, let us have a look on how to install MatLab in Windows 7 !!  Installation of Matlab requires two sections, one activation...
Page 1 of 3012345Next