Subscribe

RSS Feed (xml)

Thursday, December 1, 2011

How To Add Syntax Highlighter for Blogger/Blogspot

Syntax Highlighter are generally used for blogs, which mainly focus on scripting tutorials. We could have seen in many popular blogs using script highlighter to highlight the script. It not only highlight the script, but also give us a clear idea, how the script was formulated. This javascript can be capable of displaying css, xml, jscript, python, c# and much more supported programing languages. Most of the blogs are using the older version of Syntax Highlighter created by Alexgorbatchev. So here I am going to teach you, how to install syntax highlighter 2.1 (latest version) on your blogger / blogspot blogs. Before you could get in to the process, I recommend you to back up your template.














Step 1: 
 I made the installation steps more simple to help people implement it without any mess. Navigate to Blogger dashboard > Layout > Edit HTML  and Expand Widget Templates. Search for and replace it with the below code
<head>
















Step 2: Whenever you publish a post with script, include the script within the < pre > section
<pre class=”brush: js”>


Your script here


</pre>

Friday, September 30, 2011

C Data type - void

Linguistic meaning of void is nothing. Size of void data type is meaningless question.

What will be output of following c code?
#include<stdio.h>
int main(){
    int size;
    size=sizeof(void);
    printf("%d",size);
    return 0;
}

Output: Compilation error

If we will try to find the size of void data type complier will show an error message “not type allowed”. We cannot use any storage class modifier with void data type so void data type doesn’t reserve any memory space. Hence we cannot declare any variable as of void type i.e.
void num;   //compilation error

Use of void data type

1. To declare generic pointer
2. As a function return type
3. As a function parameter.    

Write a C program to check prime number or not without using recursion

#include<stdio.h>

int isPrime(int);

int main(){

    int num,prime;

    printf("Enter a positive number: ");
    scanf("%d",&num);

    prime = isPrime(num);

   if(prime==1)
        printf("%d is a prime number",num);
   else
      printf("%d is not a prime number",num);

   return 0;
}

int isPrime(int num){

    int i=2;

    while(i<=num/2){
         if(num%i==0)
             return 0;
         else
             i++;
    }

    return 1;
}

Prime number program in c using recursion

#include<stdio.h>

int isPrime(int);

int main(){

    int num,prime;

    printf("Enter a positive number: ");
    scanf("%d",&num);

    prime = isPrime(num);

   if(prime==1)
        printf("%d is a prime number",num);
   else
      printf("%d is not a prime number",num);

   return 0;
}

int isPrime(int num){

    static int i=2;

    if(i<=num/2){
         if(num%i==0)
             return 0;
         else{
             i++;
             isPrime(num);
         }
    }

    return 1;
}

Wednesday, September 28, 2011

C interview questions and answers

1. Write a c program without using any semicolon which output will : Hello word.


Solution: 1
void main(){
    if(printf("Hello world")){
    }
}
Solution: 2
void main(){
    while(!printf("Hello world")){
    }
}
Solution: 3
void main(){
    switch(printf("Hello world")){
    }
}

2. Write a C program to Swap two variables without using third variable.

int main()
{
    int a=5,b=10;
//process one
    a=b+a;
    b=a-b;
    a=a-b;
    printf("a= %d  b=  %d",a,b);

//process two
    a=5;
    b=10;
    a=a+b-(b=a);
    printf("\na= %d  b=  %d",a,b);
//process three
    a=5;
    b=10;
    a=a^b;
    b=a^b;
    a=b^a;
    printf("\na= %d  b=  %d",a,b);
  
//process four
    a=5;
    b=10;
    a=b-~a-1;
    b=a+~b+1;
    a=a+~b+1;
    printf("\na= %d  b=  %d",a,b);
  
//process five
    a=5,
    b=10;
    a=b+a,b=a-b,a=a-b;
    printf("\na= %d  b=  %d",a,b);
    getch();

}

3. What is dangling pointer in c?

If any pointer is pointing the memory address of any variable but after some variable has deleted from that memory location while pointer is still pointing such memory location. Such pointer is known as dangling pointer and this problem is known as dangling pointer problem.

Initially:

Later: 


4. What is wild pointer in c ?

A pointer in c which has not been initialized is known as wild pointer.

Example:

(q)What will be output of following c program?

void main(){
int *ptr;
printf("%u\n",ptr);
printf("%d",*ptr);

}

Output: Any address
Garbage value

Here ptr is wild pointer because it has not been initialized.
There is difference between the NULL pointer and wild pointer. Null pointer points the base address of segmentwhile wild pointer doesn’t point any specific memory location.

5. What is the meaning of prototype of a function ?

Prototype of a function
Answer: Declaration of function is known as prototype of a function. Prototype of a function means
(1) What is return type of function?
(2) What parameters are we passing?
(3) For example prototype of printf function is:
int printf(const char *, …);
I.e. its return type is int data type, its first parameter constant character pointer and second parameter is ellipsis i.e. variable number of arguments.


6. What are merits and demerits of array in c?

(a) We can easily access each element of array.
(b) Not necessity to declare two many variables.
(c) Array elements are stored in continuous memory location.

Demerit:
(a) Wastage of memory space. We cannot change size of array at the run time.
(b) It can store only similar type of data.



Friday, April 16, 2010

If a five digit number is input through keyboard ,write a program to print a new number by adding one to each of tis digits.

Note: If a five digit number is input through keyboard ,write a program to print a new number by adding one to each of tis digits for example a number is input is 12391 then the output should be displayed as 23502 .

#include< stdio.h>
#include< conio.h>
int main()
{
long int no,sum=0;
int rem,check=0;
clrscr( );
printf("Enter the required number:");
scanf("%ld",&no);
printf("\nGiven Number: %d",no);
while(no>0) // to store the number in reverse by adding one to each digit
{
rem=no%10;
if(rem!=9)
{
if(check==0) // imp , try to take few minutes here
sum=(10*sum)+(rem+1);
else{
sum=(10*sum)+(rem+2);
check=0;
}
} //if closed
else{
sum=(10*sum)+0;
check=1;
}
no=no/10;
} // while closed

// Afftr adding , again to print the reverse number in origianl form.

no=sum; sum=0;
while(no>0)
{
rem=no%10;
sum=(10*sum)+rem;
no=no/10;
}
printf("\nAfter Adding one: %ld",sum);
getch( );
return 0;
}

Output:
Enter the reuired Number: 12391
Given Number: 12391
After Adding one to each of its digits: 23502

Monday, March 8, 2010

Write a C program to find the greatest common divisor (GCD) of the two given positive integers.

#include< stido.h>
#include< conio.h>
int main( )
{
int a, b, res;
clrscr( );
printf("Enter the two integer values:");
scanf("%d%d", &a, &b);

for( ; ; ) //This is empty for loop.
{
res = a%b;
if( res = = 0) break;
a = b;
b = res;
}
printf("\n The GCF is : %d", res);
getch( );
return 0;
}

Write a C program that prints a given positive integer in reverse order and also sum of the individual digits involved in the given integer.

#include< stdio.h>
#include< conio.h>
int main( )
{
int no, rev=0, rem, sum=0;
clrscr( );
printf("Enter the required integer:");
scanf("%d", &no);
while(no>0)
{
rem = no%10;
rev = (10*rev)+rem;
sum = sum+rem;
no=no/10;
}
printf("\nReverse Number : %d", rev);
printf("\nSum of the individual digits : %d", sum);
getch( );

return 0;
}

Note: If any compile errors, please mail to me..

Write a C program to find the commission on a salesman's total sales

Full Question:
                      The commission on a salesman’s total sales is as follows:
a) If sales <100, then there is no commission.

b) If 100>= sales <=500, then commission = 10% of sales.

c) If sales > 500, then commission = 100+8% of sales above 500

Solution:-

#include< stdio.h>
#include< conio.h>
int main( )
{
int sales;
float comm;
clrscr( );
printf("Enter the total sales:");
scanf("%d", &sales);
if(sales<100)
printf("\nSorry no Commission, please do more sales");
else if(sales>=100 && sales<=500)
printf("\nCommission : %f ", (sales*0.1));
else
{
comm=(sales-500)*0.08;
printf("\nCommission : %f ", (comm+100));
}
getch( );
return 0;
}

Wednesday, February 17, 2010

Write a C program to find the exponential series of 1+x+x2/2!+x3/3!+.......+xn/n!

#include< math.h>
void main( )
{
int x, n, fact, i, j;
float sum=1;
clrscr( );
printf("Enter the 'x' value:");
scanf("%d",&x);
printf("\nEnter the 'n' value:");
scanf("%d",&n);
for(i=1; i< =n ; i++)
{
fact=1;
for( j=i ; j >=1; j--)
fact=fact*j;

sum=sum+(pow(x,i )/ fact);
}
printf("\nSum of the series : %f ",sum);
getch( );
}

Note:- If any errors,, plz mail to me.