Powered By Blogger

Friday, August 12, 2011

Samsung Interview Questions


1. Value of EOF??
Ans: - 1
2.struct abc
{
};
struct abc arr[10];
struct abc *p=arr;
Which statement will  increment the pointer to point the next array element?
Ans:- p=p+sizeof(abc);
4.char *a=”hello\0world\0!!”;
printf(“%d”,strlen(a));
a=a+6;
printf(“%d”,strlen(a));
a=a+7;
printf(“%d”,strlen(a));
Ans : 5 5 1 
5.int i=0;
For(;i++;printf(“%d”,i));
printf(“%d”,i);
Ans:1
6.static int i;
main()
{
If(i==5)
printf(“Samsung”);
i++;
return(i=main());
}
Ans: Stack Overflow
8.int *b={1,2,3,4,5,6,9,8};
printf(“%d”,(b+1)[5]);
Ans: 9

9.int i=512;
char *c=(char *)&i;
c[0]=1;
printf(%d”,i);
Ans: 513;
10.enum={black=2,Green=7,Red};
printf(“%d %d %d”,black,green,red}
Ans: 2 7 8
11.class abc
{
};
abc ob;
cout<
Ans: 1;
12.class abc
{
static int i;
int a;
};
abc ob;
cout<cout<
13.char c=’a’;
printf(“%d %d %d”,size(c),size(‘a’),size(“A”);
Ans: 1 4 2;
14.int i=5,*j;
void *k;
k=j=&I;
printf(“%d”,k+1);
Ans: Compilation error (but its running on gnu);
15.int i=0;
switch(i)
{
printf(“samsung”);
case 10:printf(“some string”);
break;
case 5*2:printf(“some string”);
break;
}
Ans: Error Due to Conflicting Case;
16.#define true 1
#define false -1
#define null 0
if(null)
printf(“……”);
else if(false)
printf(“true”);
Ans: True;

Data Structure :-
1.Property of Heap?
Ans: Every Node is Greater Than its Child;
2.Complexity of Binary.Log n;

Operating System :-
1.On Switch on the Computer Which Loader Come in Action First.
Ans: Boot Strap Loader
2.How to Decrease The Page Fault.
Ans :  locality of reference

Wednesday, August 10, 2011

Apology...

Sorry guys...my xams were going so cudn't post more program at that time...however i am back now..so the posting session will continue....njoy and post any C program problem that u face !!

Regards,
Parag Kr. Acharyya

Monday, May 2, 2011

Extended Pigeonhole Principle

#include<stdio.h>
#include<conio.h>
void main()
{
    int p,ph,res=0;
    printf("Enter the no. of pigeons : ");
    scanf("%d",&p);
    printf("Enter the no. of pigeon holes : ");
    scanf("%d",&ph);
    res=((p-1)/ph)+1;
    printf("There must be at least %d pigeons in each pigeon hole.\n",res);
    getch();
}

Program for funtion analysis

//This program takes as input the function in matrix form and checks
// whether the given function is injective,surjective or bijective.
#include<stdio.h>
#include<conio.h>
void main()
{
    int mat[10][10],i,j,in=0,sur=0,bij=0,m,tmp,p,q;
    printf("Enter the order of the matrix :");
    scanf("%d",&m);
    printf("Enter the matrix row-wise : \n");
    for(i=0;i<m;i++)
        for(j=0;j<m;j++)
            scanf("%d",&mat[i][j]);
    //To check whether the given function is valid or not
    for(i=0;i<m;i++)
    {
        tmp=0;
        for(j=0;j<m;j++)
            if(mat[i][j]==1)
                tmp++;
        if(tmp!=1)
        {
            printf("The given function is not valid.\n");
            break;
        }
    }
    //To print the given matrix
    printf("The given function matrix is : \n\n");
    for(i=0;i<m;i++)
        printf("\t%d",i+1);
    printf("\n\n    --------------------------");
    for(i=0;i<m;i++)
    {
        printf(" \n   |\n %d |",i+1);
        for(j=0;j<m;j++)
            printf("\t%d",mat[i][j]);
    }
    printf("\n");
    //To check if its injective
    for(i=0;i<m;i++)
    {
        in=0;
        for(j=0;j<m;j++)
            if(mat[i][j]==1)
                in++;
        if(in>1)
        {
            printf("\nThe given funtion is not injective.\n");
            break;
        }
    }
    if(in==1)
    {
        p=1;
        printf("\nThe given function is injective.\n");
    }
    //To check if its surjective
    for(i=0;i<m;i++)
    {
        sur=0;
        for(j=0;j<m;j++)
            if(mat[i][j]==1)
                sur++;
        if(sur==1)
        {
            printf("\nThe function is not surjective.\n");
            break;
        }
    }
    if(sur>1)
    {
        q=1;   
        printf("\nThe function is surjective\n");
    }
    if(p==1 && q==1)
        printf("\nThe function is bijective.\n");
    else
        printf("\nThe function is not bijective.\n");
    getch();
}