mahfooz


{ City } allahabad
< Country > india
* Profession *
User No # 19072
Total Questions Posted # 0
Total Answers Posted # 9

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 71
Users Marked my Answers as Wrong # 60
Questions / { mahfooz }
Questions Answers Category Views Company eMail




Answers / { mahfooz }

Question { CSC, 46963 }

What is the maximum total number of nodes in a tree that has
N levels? Note that the root is level (zero)


Answer

2^N-1

because root is at level 0. and there are n levels only.
so last level i.e level of leaves should be n-1. for maximum
we will consider complete binary tree which is full at level
n-1.

for 0 level -> 2^0 i.e 1 element
for 1 level -> 2^1
...
so on

for n-1 levle ->2^(n-1) nodes
---------------------------
sum = 2^n-1

Is This Answer Correct ?    2 Yes 2 No

Question { IBM, 29106 }

How to rename files and folders?


Answer

mv file/folder newfile/newfolder

Is This Answer Correct ?    31 Yes 8 No


Question { Microsoft, 16509 }

Write a routine that prints out a 2-D array in spiral order


Answer

#include
#define n 3
int main()
{
int arr[n][n]={{1,2,3},{4,5,6,},{7,8,9}};
int min=0,max=n-1,i;
while(min<=max)
{
for(i=min;i<=max;i++)
printf("%d ",arr[min][i]);
for(i=min+1;i<=max;i++)
printf("%d ",arr[i][max]);
for(i=max-1;i>=min;i--)
printf("%d ",arr[max][i]);
for(i=max-1;i>min;i--)
printf("%d ",arr[i][min]);
min++;
max--;
}
if(min==max) //this for odd case as n=3,5 etc
printf("%d \n",arr[min][min]);
return 0;
}

Is This Answer Correct ?    8 Yes 7 No

Question { IBM, 30900 }

program to get the remainder and quotant of given two
numbers with out using % and / operators?


Answer

#include
using namespace std;
int main()
{
int a,b;
cout<<"enter two number"< int r,q=0,bi,s;
cin>>a>>b;
if(a {
s=a;
bi=b;
}
else
{
s=b;
bi=a;
}
r=bi-s;
q++;
while(r>=s)
{
q++;
r=r-s;
}//endl of while.*/
cout<<"remainder is "< return 0;
}

Is This Answer Correct ?    13 Yes 8 No

Question { 3904 }

Reverse the part of the number which is present from
position i to j. Print the new number.[without using the array]
eg:
num=789876
i=2
j=5
778986


Answer

#include
#include
#include
#include
using namespace std;
int getdnum(int num)
{
int numd=0;
while(num!=0)
{
numd++;
num=num/10;
}
return numd;
}
int reversenum(int i,int j ,int d,int num)
{
int a=(num/(pow(10,d-i+1)));
int b=(num/(pow(10,d-j)));
int c=num%static_cast(pow(10,d-j));
int n=0;
int k;
for(k=0;k<=(j-i);k++)
{
n+=(b%10)*(pow(10,j-i-k));
b=b/10;
}
n=a*pow(10,d-i+1)+c+n*pow(10,d-j);
return n;

}
int main()
{
int i,j,k,l,m;
cin>>i>>j>>k;
int d=getdnum(i);
m=reversenum(j,k,d,i);
cout< return 0;
}

Is This Answer Correct ?    0 Yes 0 No

Question { 35680 }

C program to find frequency of each character in a text
file?


Answer

#include
#include
using namespace std;
int main()
{
int arr[26]={0},i;
ifstream fin;
ofstream fout;
fout.open("input.txt",ios::app);
fin.open("input.txt",ios::out);
char c;
fin>>c;
while(!fin.eof())
{
if(isalpha(c))
{
tolower(c);
switch(c)
{
case 'a':
arr[0]++;
break;
case 'b':
arr[1]++;break;
case 'c':
arr[2]++;break;
case 'd':
arr[3]++;break;
case 'e':
arr[4]++;break;
case 'f':
arr[5]++;break;
case 'g':
arr[6]++;break;
case 'h':
arr[7]++;break;
case 'i':
arr[8]++;break;
case 'j':
arr[9]++;break;
case 'k':
arr[10]++;break;
case 'l':
arr[11]++;break;
case 'm':
arr[12]++;break;
case 'n':
arr[13]++;break;
case 'o':
arr[14]++;break;
case 'p':
arr[15]++;break;
case 'q':
arr[16]++;break;
case 'r':
arr[17]++;break;
case 's':
arr[18]++;break;
case 't':
arr[19]++;break;
case 'u':
arr[20]++;break;
case 'v':
arr[21]++;break;
case 'w':
arr[22]++;break;
case 'x':
arr[23]++;break;
case 'y':
arr[24]++;break;
case 'z':
arr[25]++;break;
}
}
fin>>c;
}//endl of while.*/
for(i=0;i<26;i++)
fout<<"no of letter "<(i+65)<<" is
"< fin.close();
return 0;
}

Is This Answer Correct ?    4 Yes 29 No

Question { ABC, 24818 }

what will be the output of ls ~/..


Answer

it will show home directory :
mahfooz@mahfooz-desktop:~/diskd$ ls ~/..
mahfooz
and ls ~ will show you home/user files and directory list.

so ls ~/.. will list parent directory files and directories.

Is This Answer Correct ?    0 Yes 0 No

Question { 6410 }

While(1)
{

}
when this loop get terminate is it a infinite loop?


Answer

it is infinite loop.and it will terminate if we will call
break statement in loop.

Is This Answer Correct ?    11 Yes 3 No

Question { Nokia, 33277 }

Write a grep (or grep) command that selects the lines from
a file that have exactly three characters.


Answer

grep [a-z][a-z][a-z] filename

Is This Answer Correct ?    2 Yes 3 No