GeekInterview.com
Series: Subject: Topic:
Question: 513 of 828

The questions are as follows:


1. Write a 'c' program to read the age of 100 persons and count the number
of persons in the age group 50 to 60.use for loop and continue statements.(10
marks)

2. Write a program to read a positive integer and print its binary
equivalent.(10 marks)

3. Given two one dimensional arrays a and b which are sorted in ascending order.
write a program to merge them into a single sorted array ,c that contains every
item from arrays a and b, in ascending order.(10 marks)

4. Write a function in c that would traverse a linear singly linked list in
reverse and write out the contents in reverse order.(10 marks)

5. Write a program to read a set of integers and to separate all odd and even
numbers. write all even numbers in ascending order.(10 marks)

6. Write a program to read a real number x and find the even number nearest to
x.(10 marks)

7. Write a program to multiply two matrices of order m*n and n*p
respectively.(10 marks)

8. Write a program in'c' to implement k-map simplification technique.(10
marks)

Asked by: Interview Candidate | Asked on: Feb 8th, 2006
Showing Answers 1 - 12 of 12 Answers
sri harsha

Answered On : Mar 9th, 2006

View all answers by sri harsha

JUST PUT A COUNTER TO COUNT THE MEMBERS WITH AGE BETWEEN 50 AND 60.initialise c=0.for(i=0;i50)&&(a[i]

Yes  1 User has rated as useful.
  
Login to rate this answer.
novicecoda

Answered On : Mar 10th, 2006

View all answers by novicecoda

Please post answers in the forum too so that everyone could read them .Couuld i have the solution to the 2nd question

  
Login to rate this answer.
Casanova

Answered On : Mar 18th, 2006

View all answers by Casanova

For the 2nd// assume a stackwhile (no) { push (no%2); no/=2;}while (stack not empty) print pop ()

  
Login to rate this answer.

for 3 rd questionlet us take source arrays A & B and destinaton is Ctake three index variables I,J,K respectively for each arraytake n and m are the size of arrayswhile(i<=n &&j<=m){if (a[i]<b[j])    c[k++]=a[i++]else c[k++]=b[j++]}while(i<=n)  c[k++]=a[i++];while(j<=m) c[k++]=b[j++];then c array contains sorted data of A and B

  
Login to rate this answer.

for first question no need to take arraycount=0;for(int i=0;i<100;i++){scanf("%d",&x)if(x>=50 && x<=60) count++;}

  
Login to rate this answer.
shibaji.paul

Answered On : Apr 20th, 2006

View all answers by shibaji.paul

I am having a recursive solution to the 2nd problem, though, one can find a non-recursive solution thru the implementation of stack. void  printBinary(int n) { if (n>0) {  printBinary(n/2);  printf("%c","01"[n%2]); } else {  printf("\n"); } }

  
Login to rate this answer.
shibaji.paul

Answered On : Apr 20th, 2006

View all answers by shibaji.paul

Solution of q4 could also be made with recursion.void traverseInReverse(Node *hp){ if (hp!=NULL) {  traverseInReverse(hp->next);  printf("\n%d",hp->data); }  else {  return; }}Three cheers for recursion. (sorry for those who always wants efficiency rather than some fun coding)

  
Login to rate this answer.
swetha76

Answered On : Sep 28th, 2006

View all answers by swetha76

The answer to the first question#include<stdio.h>main(){  int age[5],i=0,count=0;  for(i=0;i<5;i++)  {     printf("Enter the age of the %d person ",i+1);     scanf("%d",&age[i]);  }  for(i=0;i<5;i++)  {    if((age[i]>=50)&&(age[i]<=60))      count++;   }  printf(" The no of the people between the age group 50 and 60 is %d",count);}

Yes  1 User has rated as useful.
  
Login to rate this answer.
shiv reddy

Answered On : Nov 13th, 2006

void agecheck(int a[]){int count=0; for(int i=0;i<100;i++){if(a[i]>50 ||a[i]<=60){}count++;}else continue;}}

Yes  1 User has rated as useful.
  
Login to rate this answer.
venkat_ceg

Answered On : Mar 20th, 2007

void main(){int i,a[15],n;clrscr();printf("Enter a no:n");scanf("%d",&n);for(i=0;i<15;i++,n>>=1)//Vary de bit size accordinglya[i]=n&1;for(i=15;i>=0;i--)printf("%d",a[i]);getch();}

  
Login to rate this answer.
econos

Answered On : May 7th, 2008

View all answers by econos

#include <stdio.h>#include <math.h>#include <stdlib.h>int main(void){    int x,y,ref;    int numbits=0;    printf("Input the desired number n");    scanf("%d",&x);    numbits=(sizeof(int)*8-1);        ref=(int)(pow(2,numbits));        for(y=0;y<=numbits;y++)    {    if((x&ref)>0)            printf("1");        else            printf("0");        x=x<<1;    }    printf("n");    return(0);}The whole numbits shebang is just to make this code machine independent. If it does not work or if you know the sizeof(int) on your machine you can just hard code the values for numbits and ref.The basic idea is that you are masking and shifting the number such that you know if a bit is set or not(MSB in our case) and this translates to a string of 1s and 0s.

  
Login to rate this answer.
Sukumar Paul

Answered On : Aug 1st, 2010

View all answers by Sukumar Paul

Answer to Question 4.Here I am giving the full program which should run without any warning and error in Turbo C++ 3.0<--------------------------------------------------------------------------------->#include<stdio.h>#include<alloc.h>struct node{   int data;   struct node *link;};typedef struct node node;void addatbeg(node **,int);void display(node **);void reverse(node **);void main(){   node *p;   p=NULL;   addatbeg(&p,10);   addatbeg(&p,129);   addatbeg(&p,67);   addatbeg(&p,23);   printf("Linklist: n");   display(&p);   reverse(&p);  //reverse linklist   printf("After Reverse linklist: n");   display(&p);}void addatbeg(node **head, int num){   node *temp;   if(*head == NULL)   {      temp = (node *)malloc(sizeof(node));      temp->data = num;      temp->link = NULL;      *head = temp;   }   else   {      temp = (node *)malloc(sizeof(node));      temp->data = num;      temp->link = *head;      *head = temp;   }}void display(node **head){    node *temp = *head;    while(temp != NULL)    {      printf("t %d",temp->data);      temp = temp->link;    }}void reverse(node **head){    node *r, *s, *temp;    r = NULL;    temp = *head;    while(temp != NULL)    {        s = r;        r = temp;        temp = temp->link;        r->link = s;    }     *head = r;}<----------------------------------------------------------------------------->The logic behind the program is:1) First create a linklist wid some data(with the help of  addatbeg function)2) Reverse the linklist(with the help of reverse function)3) Display the linklist(with the help of display function)

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.