# 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)

Showing Answers 1 - 12 of 12 Answers

#### sri harsha Profile Answers by sri harsha

• Mar 9th, 2006

JUST PUT A COUNTER TO COUNT THE MEMBERS WITH AGE BETWEEN 50 AND 60.initialise c=0.for(i=0;i<100;i++){ scanf("%d",&a[i]); if((a[i]>50)&&(a[i]<60)){ c++;}}

#### novicecoda Profile Answers by novicecoda

• Mar 10th, 2006

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

#### Casanova Profile Answers by Casanova

• Mar 18th, 2006

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

#### venkatesh Profile Answers by venkatesh Questions by venkatesh

• Mar 27th, 2006

for 3 rd question

let us take source arrays A & B and destinaton is C

take three index variables I,J,K respectively for each array

take n and m are the size of arrays

while(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

#### venkatesh Profile Answers by venkatesh Questions by venkatesh

• Mar 28th, 2006

for first question no need to take array

count=0;

for(int i=0;i<100;i++)

{

scanf("%d",&x)

if(x>=50 && x<=60) count++;

}

#### shibaji.paul Profile Answers by shibaji.paul

• Apr 20th, 2006

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");
}
}

#### shibaji.paul Profile Answers by shibaji.paul

• Apr 20th, 2006

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)

#### swetha76 Profile Answers by swetha76

• Sep 28th, 2006

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);
}

#### shiv reddy

• 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;

}

}

#### venkat_ceg

• 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 accordingly
a[i]=n&1;
for(i=15;i>=0;i--)
printf("%d",a[i]);
getch();
}

#### econos Profile Answers by econos

• May 7th, 2008

#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.

#### Sukumar Paul Profile Answers by Sukumar Paul

• Aug 1st, 2010

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;
};
typedef struct node node;
void display(node **);
void reverse(node **);
void main()
{
node *p;
p=NULL;

display(&p);
printf("After Reverse linklist: n");
display(&p);

}

{
node *temp;
{
temp = (node *)malloc(sizeof(node));
temp->data = num;
}
else
{
temp = (node *)malloc(sizeof(node));
temp->data = num;

}
}
{
node *temp = *head;
while(temp != NULL)
{
printf("t %d",temp->data);
}
}

{
node *r, *s, *temp;
r = NULL;

while(temp != NULL)
{
s = r;
r = temp;

}
}

<----------------------------------------------------------------------------->

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)

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

Send   Reset