ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories >> Software >> Programming-Languages >> C
 
 


 

Back to Questions Page
 
Question
how to generate sparse matrix in c
Rank Answer Posted By  
 Question Submitted By :: Chandrakala_13
I also faced this Question!!   © ALL Interview .com
Answer
//PROGRAM TO CREATE A REPRESENTATION OF SPARSE MATRIX AND 
PERFORM OPERATIONS

#include<stdio.h>
#include<conio.h>
void implement(int[][10],int,int,int[][10]);
void add(int[][10],int,int,int[][10],int[][10]);
void sub(int[][10],int,int,int[][10],int[][10]);
void transpose(int[][10],int,int[][10]);
void main()
{
int a[10][10];
int b[10][10];
int c[10][10];
int d[10][10];
int e[50][10];
int row,col,k,l,ch;
char che;
clrscr();
printf("enter the no. of rows\t:");
scanf("%d",&row);
printf("\n enter the no. of coloms\t:");
scanf("%d",&col);
printf("\n enter the elements of sparse matrix \t:");
for(k=0;k<row;k++)
{
for(l=0;l<col;l++)
{
printf("\n element at [%d][%d]\t",k,l);
scanf("%d",&a[k][l]);
}
}
printf("sparse matrix is \n");
for(k=0;k<row;k++)
{
for(l=0;l<col;l++)
{
printf("%d\t",a[k][l]);
}
printf("\n");
}
do
{
printf("\n      CYNET MENU\n");
printf("1:REPRESENTATION\n");
printf("2:ADDITION\n");
printf("3:SUBTRACTION\n");
printf("4:TRANSPOSE\n");
printf("5:EXIT\n");
printf("enter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
       implement(a,row,col,b);
       break;
case 2:

printf("\n enter the elements of second sparse matrix \t:");
for(k=0;k<row;k++)
{
for(l=0;l<col;l++)
{
printf("\n element at [%d][%d]\t",k,l);
scanf("%d",&c[k][l]);
}
}
printf("sparse matrix is \n");
for(k=0;k<row;k++)
{
for(l=0;l<col;l++)
{
printf("%d\t",c[k][l]);
}
printf("\n");
}
implement(a,row,col,b);
implement(c,row,col,d);
add(b,row,col,d,e);
       break;
case 3:
printf("\n enter the elements of second sparse matrix \t:");
for(k=0;k<row;k++)
{
for(l=0;l<col;l++)
{
printf("\n element at [%d][%d]\t",k,l);
scanf("%d",&c[k][l]);
}
}
printf("sparse matrix is \n");
for(k=0;k<row;k++)
{
for(l=0;l<col;l++)
{
printf("%d\t",c[k][l]);
}
printf("\n");
}
implement(a,row,col,b);
implement(c,row,col,d);
sub(b,row,col,d,e);
       break;
case 4:
       implement(a,row,col,b);
       transpose(b,col,c);
       break;

case 5:
       exit();
default:
	printf("you entered wrong choice\n");
}
printf("do you want to continue(y\Y):");
che=getche();
//clrscr();
}while(che=='y'||che=='Y');
getch();
}
void implement(int a[][10],int row,int col,int b[][10])
{
int g=1,nz=0,k,l;
for(k=0;k<row;k++)
{
for(l=0;l<col;l++)
{
if(a[k][l]!=0)
{
nz=nz+1;
}
}
}
b[0][0]=row;
b[0][1]=col;
b[0][2]=nz;
for(k=0;k<row;k++)
{
for(l=0;l<col;l++)
{
if(a[k][l]!=0)
{
b[g][0]=k;
b[g][1]=l;
b[g][2]=a[k][l];
g++;
}
}
}
printf("implementation of sparse matrix is\n");
for(k=0;k<g;k++)
{
for(l=0;l<3;l++)
{
printf("%d\t",b[k][l]);
}
printf("\n");
}
}
void add(int b[][10],int row,int col,int d[][10],int e[]
[10])
{
int p1=1,p2=1,i=1;
int k,l;
if(b[0][0]!=d[0][0])
{
printf("addition is not possible\n");
}
else
{
while(p1<=b[0][2]&&p2<=d[0][2])
{
if(b[p1][0]==d[p2][0])
{
 if(b[p1][1]<d[p2][1])
  {
  e[i][0]=b[p1][0];
  e[i][1]=b[p1][1];
  e[i][2]=b[p1][2];
  i++;
  p1++;
  }
else if(b[p1][1]>d[p2][1])
  {
  e[i][0]=d[p2][0];
  e[i][1]=d[p2][1];
  e[i][2]=d[p2][2];
  i++;
  p2++;
  }
  else if(b[p1][1]==d[p2][1])
  {
  e[i][0]=d[p1][0];
  e[i][1]=d[p1][1];
  e[i][2]=b[p1][2]+d[p2][2];
  if(e[i][2]!=0)
  {
   i++;
    }
    p1++;
    p2++;
  }

  }
  else if(b[p1][0]<d[p2][0])
  {
  e[i][0]=b[p1][0];
  e[i][1]=b[p1][1];
  e[i][2]=b[p1][2];
  i++;
  p1++;
  }
  else if(b[p1][0]>d[p2][0])
  {
  e[i][0]=d[p2][0];
  e[i][1]=d[p2][1];
  e[i][2]=d[p2][2];
  i++;
  p2++;
  }
  }
  if(p1!=b[0][2])
  {
  while(p1<=b[0][2])
  {
  e[i][0]=b[p1][0];
  e[i][1]=b[p1][1];
  e[i][2]=b[p1][2];
  i++;
  p1++;
  }
  }
  else if(p2!=d[0][2])
  {
  while(p2<=d[0][2])
  {
  e[i][0]=d[p2][0];
  e[i][1]=d[p2][1];
  e[i][2]=d[p2][2];
  i++;
  p2++;
  }
  }
  e[0][0]=row;
  e[0][1]=col;
  e[0][2]=i-1;


  printf("matrix after addition\n");
  for(k=0;k<i;k++)
  {
  for(l=0;l<3;l++)
  {
  printf("%d\t",e[k][l]);
  }
  printf("\n");
  } }
   }

 void sub(int b[][10],int row,int col,int d[][10],int e[]
[10])

{
int p1=1,p2=1,i=1;
int k,l;
if(b[0][0]!=d[0][0])
{
printf("subtraction is not possible\n");
}
else
{
while(p1<=b[0][2]&&p2<=d[0][2])
{
if(b[p1][0]==d[p2][0])
{


 if(b[p1][1]<d[p2][1])
  {
  e[i][0]=b[p1][0];
  e[i][1]=b[p1][1];
  e[i][2]=b[p1][2];
  i++;
  p1++;
  }
 else if(b[p1][1]>d[p2][1])
  {
  e[i][0]=d[p2][0];
  e[i][1]=d[p2][1];
  e[i][2]=d[p2][2];
  i++;
  p2++;
  }
  else if(b[p1][1]==d[p2][1])
  {
  e[i][0]=d[p1][0];
  e[i][1]=d[p1][1];
  e[i][2]=b[p1][2]-d[p2][2];
  if(e[i][2]!=0)
  {
   i++;
    }
    p1++;
    p2++;
  }

  }
  else if(b[p1][0]<d[p2][0])
  {
  e[i][0]=b[p1][0];
  e[i][1]=b[p1][1];
  e[i][2]=b[p1][2];
  i++;
  p1++;
  }
  else if(b[p1][0]>d[p2][0])
  {
  e[i][0]=d[p2][0];
  e[i][1]=d[p2][1];
  e[i][2]=d[p2][2];
  i++;
  p2++;
  }
  }
  if(p1!=b[0][2])
  {
  while(p1<=b[0][2])
  {
  e[i][0]=b[p1][0];
  e[i][1]=b[p1][1];
  e[i][2]=b[p1][2];
  i++;
  p1++;
  }
  }
  else if(p2!=d[0][2])
  {
  while(p2<=d[0][2])
  {
  e[i][0]=d[p2][0];
  e[i][1]=d[p2][1];
  e[i][2]=d[p2][2];
  i++;
  p2++;
  }
  }

  e[0][0]=row;
  e[0][1]=col;
  e[0][2]=i-1;


  printf("matrix after subtraction\n");
  for(k=0;k<=i;k++)
  {
  for(l=0;l<3;l++)
  {
  printf("%d\t",e[k][l]);
  }
  printf("\n");
  } }
  }

  void transpose(int b[][10],int col,int c[][10])
  {
  int i,j,k,temp;

  for(i=0;i<=b[0][2];i++)
  {
  c[i][0]=b[i][1];
  c[i][1]=b[i][0];
  c[i][2]=b[i][2];
  }
  for(i=1;i<=b[0][2];i++)
  {
  for(j=i+1;j<=b[0][2];j++)
  {
   if(c[i][0]>c[j][0])
   {
    for(k=0;k<3;k++)
    {
     temp=c[i][k];
     c[i][k]=c[j][k];
     c[j][k]=temp;
     }
     }

     }
     }
     printf("transpose of matrix is\n");
     for(i=0;i<=c[0][2];i++)
     {
     for(j=0;j<3;j++)
     {
     printf("%d\t",c[i][j]);
     }
     printf("\n");
     }
     }
 
0
Aman Celly
 
 
Question
how to copy a string without using c function
Rank Answer Posted By  
 Question Submitted By :: Chandrakala_13
I also faced this Question!!   © ALL Interview .com
Answer
#include<stdio.h>
#include<conio.h>
void str_cpy(char *,char *);
void main()
{
char a[20],b[20];
printf("enter the string to be copied:");
gets(b);
str_cpy(a,b);
puts(a);
getch();
}
void str_cpy(char *str,char *str1)
{
if(str1!='\0')
{
*str=*str1;
str_cpy(++str,++str1);
}
str='\0';
}


thank u
 
0
Vignesh1988i
 
 
Answer
int main(int argc, char *argv[])
{
   char _output[200];
   memset(_output,'\0',200);
   if(argc < 2)
   {
       printf("Usage: <%s> <String -1>\n",argv[0]);
       return -1;
   }
   StrCpy(_output,argv[1]);
   printf("The Final String is::: \n[%s]\n",_output);
   return 0;
}

int StrCpy(char *_output, const char *_input1)
{
  int _cntr1 = 0;
  while(*(_input1 + _cntr1) != NULL)
  {
      *(_output + _cntr1) = *(_input1 + _cntr1);
      _cntr1++;
  }
  return 0;
}
 
0
Ankitecian
 
 
 
Answer
#include<stdio.h>
#include<conio.h>
int main()
{
    char a[40],b[40];
    int i=0,c,j;
   printf("\nEnter the first string ");
   while((a[i++]=getchar())!='\n');
   for(c=0;c<i;c++)
   {
                   b[c] = a[c];
   }
  
   for(j=0;j<i;j++)
   {
                   printf("%c",b[j]);
   }
   getch();
}
 
0
Ruchi
 
 
Answer
main()
{
   char s[20],s2[20];
   printf("enter the string");
   scanf(" %[^\n]",s);
   for(i=0;s[i];i++)
      s[i]=s2[i];
      s2[i]='\0';
    printf("%s",s2);
}
 
0
Valli
 
 
Answer
sorry 
after for loop it is not 
s[i]=s2[i]
but 
correct one is 
s2[i]=s[i];
 
0
Valli
 
 
Question
how to find string length wihtout using c function?
Rank Answer Posted By  
 Question Submitted By :: Chandrakala_13
I also faced this Question!!   © ALL Interview .com
Answer
#include<stdio.h>
#include<conio.h>
int str_len(char *)
void main()
{
char s[30];
int count;
printf("enter the string :");
gets(s);
count=str_len(s);
printf("the length is :%d",count);
getch();
}
int str_len(char *a)
{
int i=0;
while(*a!='\0')
a++;
i++;
}
return i;
}

thank u
 
0
Vignesh1988i
 
 
Answer
char *a="india";
for(i=0;a[i]!='\0';i++);
printf("the length is :%d",i);
 
0
Ivr
 
 
Answer
int StrLen(const char *_input)
{
  int _len = 0;
  while( *(_input + _len) != NULL)
  {
     _len++;
  }
  return _len;
}
 
0
Ankitecian
 
 
Answer
#include<conio.h>
#include<stdio.h>
int main()
{
    char a[10];
    int i=0,c,length=0;
    printf("\nEnter the string ");
    while((a[i++]=getchar())!='\n');
    printf("\nThe lengh of the string is ");
    i=i-1;
    printf("%d",i);
    getch();
}
 
0
Ruchi
 
 
Question
write a program in c language for the multiplication of two 
matrices using pointers?
Rank Answer Posted By  
 Question Submitted By :: Sbabli90
This Interview Question Asked @   Ignou
I also faced this Question!!   © ALL Interview .com
Answer
main()
{
int mat1[3][3] = {1,2,3,4,5,6,7,8,9};
int mat2[3][3] = {1,2,3,4,5,6,7,8,9};
int res[3][3];
int i,j,k;
for (i=0; i<3; i++)
for (j=0; j<3; j++)
res[i][j] = 0;
for (i=0; i<3; i++)
for (j=0; j<3; j++)
for (k=0; k<3; k++)
*(*(res + i) + j) += (*(*(mat1 + i) + k)) * (*(*(mat2 + k) 
+ j));

for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
printf ("%d\t", res[i][j]);
printf ("\n");
}
printf("\n");
}
 
1
Syed Fakheruddin Ahmad
 
 
Answer
9
 
0
Arum Kumar Mishra
[-NA-]
 
 
Answer
#include<stdio.h> 
#include<conio.h> 
int main() 
{ 
    int mul(int,int); 
    int n1,n2,f=1,ans; 
    while(f==1) 
    { 
        printf("\n***MULTIPLICATION OF TWO NATURAL 
NUMBERS***"); 
        printf("\nEnter Two Numbers: "); 
        scanf("%d %d",&n1,&n2); 
        if(n1<=0||n2<=0) 
        { 
            printf("\nInvalid Choice..."); 
            printf("\nDo You Want To Try 
Again...\n1.Yes\n2.No"); 
            scanf("%d",&f); 
        } 
        else 
        { 
            printf("\nAns = %d",mul(n1,n2),"\n"); 
            printf("\nDo You Want To 
Continue:\n1.Yes\n2.No\n"); 
            scanf("%d",&f); 
        } 
    } 
} 
int mul(int a,int b) 
{ 
    return((b-1)*a+a); 
}
 
0
Tutu
[-NA-]
 
 
Answer
#include<stdio.h>
#include<conio.h>
int main()
{
    int n,m,i,j,k;
    int a[38][38],b[38][38],p[38][38];
    printf("\nEnter the number of rows and coloumns ");
    scanf("%d %d",&n,&m);
    printf("\nEnter the elements of first matrix ");
    for(i=0;i<n;i++)
    {
                    for(j=0;j<m;j++)
                    {
                                    scanf("%d",(*(a+i)+j));
                    }
    }
    printf("\nMatrix is ");
     for(i=0;i<n;i++)
    {
                     printf("\n");
                    for(j=0;j<m;j++)
                    {
                                    printf("%d",*(*(a+i)+j));
                                    printf("\t");
                    }
    }
     printf("\nEnter the elements of second matrix ");
    for(i=0;i<n;i++)
    {
                    for(j=0;j<m;j++)
                    {
                                    scanf("%d",(*(b+i)+j));
                    }
    }
    printf("\nMatrix is ");
     for(i=0;i<n;i++)
    {
                     printf("\n");
                    for(j=0;j<m;j++)
                    {
                                    printf("%d",*(*(b+i)+j));
                                    printf("\t");
                    }
    }
    printf("\nAfter multiplication ");
    for(i=0;i<n;i++)
    {
                    for(j=0;j<m;j++)
                    {
                    p[i][j]=0;
                    for(k=0;k<n;k++)
                    {
                    p[i][j]+=a[i][k]*b[k][j];
                    }
                    }
                    }
                    for(i=0;i<n;i++)
                    {
                    printf("\n");
                    for(j=0;j<m;j++)
                    {
                    printf("%d",*(*(p+i)+j));
                    printf("\t");
                    }
                    }
                                                           
                        
    getch();
}
 
0
Ruchi
[-NA-]
 
 
Answer
// write a program to multipication of a matrix
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void main()
{
int *ptr1,*ptr2,*ptr3;
int m,n,i,j,k;
printf("enter m & n=");
scanf("%d%d",&m,&n);
ptr1=(int*)malloc((m*n)*sizeof(int));
ptr2=(int*)malloc((m*n)*sizeof(int));
ptr3=(int*)malloc((m*n)*sizeof(int));
printf("enter elements of 1st matrix=");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",((ptr1+i)+j)) ;
}
}
printf("enter elements of 2nd matrix=");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",((ptr2+i)+j)) ;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
*((ptr3+i)+j)=0;
for(k=0;k<n;k++)
{
*((ptr3+i)+j)=*((ptr3+i)+j)+(*((ptr1+i)+j))*(*((ptr2+j)+k));
}
}
}
printf("multipication is=\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",*((ptr3+i)+j)) ;
}
printf("\n");
}
getch();
}
 
0
Shankey Narang
[-NA-]
 
 
Question
Dear Sir,
we are required the bubble sorting programs 

Regs
Prem
Rank Answer Posted By  
 Question Submitted By :: Premshriwas
I also faced this Question!!   © ALL Interview .com
Answer
DESCENDING ORDER Bubble sorting

#include<stdio.h>
#include<conio.h>
void main()
{
int  a[100],n;
printf("enter the number of elements :");
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
 for(j=0;j<n;j++)
   if(a[j]<a[j+1])
     {
      temp=a[j];
      a[j]=a[j+1];
      a[j+1]=temp;
     }
for(i=0;i<n;i++)
printf("%d\n",a[i]);
getch();
}


thank u
 
0
Vignesh1988i
 
 
Question
program for comparing 2 strings without strcmp()
Rank Answer Posted By  
 Question Submitted By :: Pinky
I also faced this Question!!   © ALL Interview .com
Answer
#include<stdio.h>
#include<conio.h>
void main()
{
 char st1[10],st2[10];
 int i,sl1=0,sl2;
 clrscr();
 printf("\nEnter String1:");
 scanf("%s",st1);
 printf("\nEnter String2:");
 scanf("%s",st2);
 for(i=0;st1[i]!='\0';i++)
   sl1=sl1+1;
 for(i=0;st2[i]='\0';i++)
   sl2=sl2+1;
 if(sl1!=sl2)
 {
  printf("\nString is not equal.");
 }
 else
 {
  for(i=0;st1[i]!='\0' || st2[i]!='\0';i++)
  {
    if(st1[i]!=st2[i])
    { f=1; }
   }
  if(f==1)
    printf("\nString is not equal.");
  else
    printf("\nString is equal.");
 }
 getch(); 
}
 
0
Karthikeyan N P
 
 
Answer
int StrCmp(const char *_input1, const char *_input2)
{
  int _cntr1 = 0;
  int _flg = 0;
  while(*(_input1 + _cntr1) != NULL || *(_input2 + _cntr1) !
= NULL)
  {
      if(*(_input1 + _cntr1) != *(_input2 + _cntr1))
      {
         _flg = -1;
      }
      _cntr1++;
  }
  return _flg;
}
 
0
Ankitecian
 
 
Answer
#include<stdio.h>
#include<conio.h>
int main()
{
    char a[20],b[20];
    int l1,l2,i=0,j=0;
    printf("\nEntert the first string ");
    while((a[i++]=getchar())!='\n');
    l1=i-1;
    printf("\nEnter the second string ");
    while((b[j++]=getchar())!='\n');
    l2=j-1;
    if(l1>l2)
    {
             printf("\nThe first string is greater than the
second ");
    }
    else if(l2>l1)
    {
        printf("\n Second string is greater than the first ");
    }
    else
    {
        printf("\nBoth the strings are equal ");
    }
    getch();
}
 
0
Ruchi
 
 
Question
what is data structure
Rank Answer Posted By  
 Question Submitted By :: Adil.90@yahoomail.com
I also faced this Question!!   © ALL Interview .com
Answer
A data structure in computer science is a to store data in a
computer that can be used efficiently.It is an organitzation
of mathematical and logical concepts of data.
 
0
Ali
 
 
Answer
data structure is nothing but basically C  , in which our data can be efficiently handled without any memory wastages and data can be easily be retrieved for manipulations and strengthens the data security since the usage of POINTERS are more here........

thank u
 
0
Vignesh1988i
[No]
 
 
Answer
Data may be organized in different ways.The logical or
mathematical model of a particular organization of data is
called a data structure.
 
0
Cynthia
[No]
 
 
Answer
Data may be organized in different ways.The logical or
mathematical model of a particular organization of data is
called a data structure.
 
0
Cynthia
[No]
 
 
Question
code for copying two strings  with out strcpy() function.
Rank Answer Posted By  
 Question Submitted By :: Pinky
I also faced this Question!!   © ALL Interview .com
Answer
#include<iostream.h>
void main(void)
{
char first[]="sajid";
char second[6];
int index;
for(index=0;index<6;index++)
{
second[index]=first[index];
}
cout<<second;
}
 
0
Ali
 
 
Answer
well, we could also have a string accepted at run time by
use of scanf.

To take care of such cases.

char *mystrcpy(char src[])
{
     char *dest = NULL;
     int indx = 0, len = 0;
     if (!src) return dest;
     len = strlen(src);  
     dest = (char *)malloc(sizeof(char) * len + 1);
     while (; src[indx] ; dest[indx++]=src[indx]);
     dest[indx]='\0'
     return (dest)
}
Please do update if any one finds any issue with the code
segment - in terms of any error or any optimisation
 
0
Reachhary
 
 
Answer
#include<stdio.h>
#include<conio.h>
void str_cpy(char *,char *);
void main()
{
char a[30],b[20];
printf("enter the string to be copied :");
gets(b);
str_cpy(a,b);
printf("the final string is :");
puts(a);
getch();
}
void str_cpy(char *a,char *b)
{
if(*b!='\0')
{
*a=*b;
str_cpy(++a,++b);
}
*a='\0';
}

thank u
 
0
Vignesh1988i
 
 
Answer
int main(int argc, char *argv[])
{
   char _output[200];
   memset(_output,'\0',200);
   if(argc < 2)
   {
       printf("Usage: <%s> <String -1>\n",argv[0]);
       return -1;
   }
   StrCpy(_output,argv[1]);
   printf("The Final String is::: \n[%s]\n",_output);
   return 0;
}

int StrCpy(char *_output, const char *_input1)
{
  int _cntr1 = 0;
  while(*(_input1 + _cntr1) != NULL)
  {
      *(_output + _cntr1) = *(_input1 + _cntr1);
      _cntr1++;
  }
  return 0;
}
 
0
Ankitecian
 
 
Answer
#inclue<stdio.h>
main()
{
char str1[10],str2[10];
int i=0;
printf("enter the str1");
gets(str1);
while(str1[i]!='\0')
{
str2[i]=str1[i];
i++;
}
puts(str2);
}
 
0
Suman_kotte
 
 
Question
Determine if a number is a power of 2 at O(1).
Rank Answer Posted By  
 Question Submitted By :: Or
I also faced this Question!!   © ALL Interview .com
Answer
int Isnopowerof2(int n)
{
    if (n & n-1) 
       return 0;
    return 1;
}
 
4
Hary
 
 
Question
Is it possible to create recycle bin in mobiles?
Rank Answer Posted By  
 Question Submitted By :: Manojvarma
I also faced this Question!!   © ALL Interview .com
Answer
yes. it is possible.
 
0
Abhradeep Chatterjee
 
 
Answer
but how
 
0
Mani
 
 
Question
which type of  question asked from c / c++ in interview.
Rank Answer Posted By  
 Question Submitted By :: Matrix_abhi2711
I also faced this Question!!   © ALL Interview .com
Answer
conceptual questions which proves that the basic idea of 
the candidate is clear.
 
0
Abhradeep Chatterjee
 
 
Answer
Any Type.
 
0
Abhradeep Chatterjee
 
 
Question
let's take a code 

struct FAQ
{
int a;
char b;
float c;
double d;
int a[10];
}*temp;

now explain me how the memory will be allocated for the 
structure FAQ and what address will be in the structure 
pointer (temp)....................
Rank Answer Posted By  
 Question Submitted By :: Vignesh1988i
I also faced this Question!!   © ALL Interview .com
Answer
Memory allocated will be word aligned in nature.
e.g. for int the address would be allocated as a multiple of
4 .... Next char would start the n+1 where n = multiple of 4.

Similarly next.... 
when we do sizeof structure we get 60 bytes...
But originally , it should be
4 + 1+ 4+ 8 + 4 *10 = 57 bytes.
The extra three bytes are from char where 3 bytes are wasted
in memory space.
 
0
Vrushali
 
 
Answer
please be clear ...............i could not understand ur
reply fully.... please brief it .......sorry
 
0
Vignesh1988i
 
 
Answer
Sorry ..  i did not get your context....
 
0
Vrushali
 
 
Answer
see from the above code i want wat address will get stored in the structure pointer temp??????????????
 
0
Vignesh1988i
 
 
Answer
55 BYTES OF MEMORY NEEDED.
ADDRESSS-IS BY DEFAULT
 
0
Sumanshu
 
 
Answer
As already told by vrushali memory to a structure is always
allocated along word boundaries. So int would fetch 4 bytes
(assumed that the int in ur machine takes 4 and word is 4
bytes). Similarly char would take 1 but since the next entry
i.e. float requires 4 so char would be given 4 (3 extra )
and so on for the remaining summing upto 60 as already
indicated.

By default temp would have the base address of the structure
i.e. pointing to the first integer i.e. 'a' in our case.
 
0
Reachhary
 
 
Answer
when u declare a structure there is no memory allocated yet.
memory will be allocated after creating an 
instance(variable).Here, there is an instance (pointer
variable pointing to structure FAQ ). But the compiler
allocated only 4 bytes of memory for the variable temp. But
the this temp contains garbage address or  0 if it is
global. to allocated memory of size 60 byte u need to use
malloc function.

Ex: temp = malloc ( sizeof ( struct FAQ ) );

now 60 bytes of memory has been allocated from the heap. and
the starting address of this memory chunk is stored in
variable temp.
 
0
Sharan
 
 
Question
How to write a code for random pick from 1-1000 numbers?
The output should contain the 10 numbers from the range
1-1000 which should pick randomly, ie ,for each time we run
the code we should get different outputs.
Rank Answer Posted By  
 Question Submitted By :: Umesh Koodali
This Interview Question Asked @   NetApp
I also faced this Question!!   © ALL Interview .com
Answer
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int main(void)
{
   int i;

   randomize();
   printf("Ten random numbers from 0 to 1000\n\n");
   for(i=0; i<10; i++)
       printf("%d\n", rand() % 100);
   return 0;

}
 
3
Navdeep Singh
 
 
Answer
the  above answer is correct.
 
0
Abhradeep Chatterjee
 
 
Answer
Execute and verify it once
 
0
Rama Krishna
 
 
Answer
I am Sorry, I executed the Code and it does not work.
Thanks to Rama Krishna.
 
0
Abhradeep Chatterjee
 
 
Answer
So anybody know the right answer?
 
0
Umesh Koodali
 
 
Answer
if the randomize(); doesn't work
replace it with srand ((unsigned) time (NULL));
 
0
Sharan
 
 
Answer
First program is wrong ,randomize is undefined you just
check it.
 
0
Rama Krishna
 
 
Answer
it is not the correct answer because the range they asked 0-
1000 so need to to %1000. :-)
 
0
Kap
 
 
Answer
hi... guys... what i think is that we can make use of files... because it is asked that each time we run the code it must generate different numbers..... .. only in file it will be saved pernmently .... 
          first let us create a file to give a starting number to start the generation....
          let us assume that we have created a file named random.txt... in that we have a number 21 (assumption)..
#include<stdio.h>
#include<conio.h>
void main()
{
FILE  *pointer,*pointer1;
char ch;
int r=0,n[10],count=0;
pointer=fopen("random.txt","r");
while(1)
{
ch=fgetc(pointer);
if(ch==EOF)
break;
else
r=r+((ch-'0')*10); // to change  char to int
}
int j=31;
for(int i=0;i<10;i++)
{
printf("%d",r+12+j);
if(i%2==0)
j+=42;
}
r+=23;
for(i=0;r>0;i++)
{
n[i]=r%10;
r=r/10;
}
pointer1=fopen("random.txt","w");
fflush(stdin);
i=0;
while(1)
{
count++;
ch=n[i]+'0';
if(count!=2)
{
fputc(ch,pointer1);
count++;
}
else
break;
i++;
}
getch();
}

this is only for a sample simple random number generation.....

thank u
 
0
Vignesh1988i
 
 
Answer
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void main()
{
int i;
randomize();
printf("\n Ten random numbers between 1 and 1000 are \n");
for(i=0;i<10;i++)
printf("%d  ",random(1000)+1);
getch();
}
 
0
Dayquest
 
 
Answer
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int i;
srand(time(NULL));
printf("\n Ten random numbers between 1 and 1000 are \n");
for(i=0;i<10;i++)
    printf("%d  ",(rand() % 1000) + 1);
return EXIT_SUCCESS;
}
 
0
Kameshwar
 
 
Answer
The best way to solve this problem would be to create a hash
function and apply the current time to as the argument to
the hash function. the hash function should be designed to
return a number between 1 to 1000.
 
0
Nischal E Rao
 
 
Question
do ne body have any idea about the salary for the we r going
to have interview.
yup .. u got it right ..i m talking abt NIC.
Rank Answer Posted By  
 Question Submitted By :: Guest
I also faced this Question!!   © ALL Interview .com
Answer
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,r,c,a[10][10],b[10]][10],c[10][10],k;
clrscr();
printf("enter the size of array");
scanf("%d%d",&r,&c);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
scanf("%d",a[i][j]);
}
printf("enter elements of 2nd matrix");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
scanf("%d",&b[i][j]);
}
for(i=0;i,r;i++)
{
for(k=0;k<r;k++)
{
for(j=0;j<r;j++)
c[i][k]=c[i][k]+a[i][j]*b[j][k];
}
}
}
 
0
Manojbatra071
 
 
 
Back to Questions Page
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com