Answered by:
C/cPP puzzles contd...
Question

this is in continuation to the previous thread http://forums.microsoft.com/SamVaad/AddPost.aspx?PostID=1659552&SiteID=43&ReturnUrl=Tuesday, May 29, 2007 12:06 PM
Answers

arre yaar.
why don't you post problems here?
let me also solve them.
& side by side i'll also post questionsTuesday, May 29, 2007 3:10 PM 
Ok, i have a nice one for you....
write a program which gives the Nth largest number from an array.. the array is not in sorted form.. but you have to do it without sorting the array....Tuesday, May 29, 2007 3:57 PM 
//let arr[size] be the array
void main()
{
int n_larg,i,j,index;
printf("enter the number of the largest number which you find to find\n");
scanf("%d",&n_larg);
for(i=1 ; i<=n_larg ; i++)
{
n_larg=arr[0];
index=0;
for(j=0;j<size;j++)
if(n_larg<arr[j])
{ n_larg=arr[j]; index=j;}
if(i!=n_larg)
arr[index]=0;
}
printf("the %dth largest number is %d at an index %d",n_larg,arr[index] , index);
}Wednesday, May 30, 2007 2:01 AM 
The code is having problems.. try to run it.. i ran it and it had problems... I will post my code.. have a look at it..
// This program will find the Kth smallest number from the list without sorting.
#include<stdio.h>
#include<conio.h>
void main()
{
int data[30], i, j, n, k, temp=30000, min;
printf("Please give the number of entries in the series : ");
scanf("%d",&n);
printf("Please give the data :\n");
for(i=0;i<n;i++)
scanf("%d",&data[i]);
printf("Please give the value of K (the Kth smallest number) : ");
scanf("%d",&k);
for(j=k; j>0; j)
{
min=30000;
for(i=0; i<n; i++)
{
if (data[i]<min && data[i]>temp)
min=data[i];
}
temp = min;
}
printf("The %d Smallest Number = %d", k,temp);
getch();
}
This program is for the smallest one.. you can create one for the greatest one from thisWednesday, May 30, 2007 4:51 AM 
well, my code is running well here.
which problems have you encountered?
& after looking at your code, our logics seem to be pretty same.
& if i'm right then say it
&
post another query hereWednesday, May 30, 2007 4:57 AM 
sorry small mistake.
//let arr[size] be the array
void main()
{
int n_larg,i,j,index,lar;
printf("enter the number of the largest number which you find to find\n");
scanf("%d",&n_larg);
for(i=1 ; i<=n_larg ; i++)
{
lar=arr[0];
index=0;
for(j=0;j<size;j++)
if(lar<arr[j])
{ lar=arr[j]; index=j;}
if(i!=n_larg)
arr[index]=0;
}
printf("the %dth largest number is %d at an index %d",n_larg,arr[index] , index+1);
}
check it nowWednesday, May 30, 2007 5:08 AM 
Yup its working fine... good....
Now answer this... write a code to create a series like this....
111
112
113
121
122
123
131
132
133
211
212
.................
332
333
This is the case of generating all the permutation of N numbers.. like we have 3 above and the possible set of 3 numbers is generated, like 1 1 1 is one set 1 2 3 is another set...
So you take 2 input
1) the number N
2) The size of the set K....Wednesday, May 30, 2007 7:14 AM 
well, this can be done using nested loops technique.
here's a new problem.
IMPLEMENT star topology using C.Monday, June 4, 2007 2:46 AM 
What is a star topology???Monday, June 4, 2007 6:33 AM

it's a network topology.
haven't you studied networking?Monday, June 4, 2007 6:37 AM 
ok.
so i have to give you another problem.
here it is.
write a program which will take input string from user & list it's contents files, subdirectories, children sub directories.
for e.g.
let we have a folder named sunil in d:/
this folder contains the following folders.
folders within sunil files/folders within each folder
sameer file1, sayhello, .....
varun ............
harshil ...........
& files :
program
then program should output:
sameer
file1,sayhello
varun
..........,.......
harshil
..........,............
programMonday, June 4, 2007 11:12 AM 
it's easy.
i'm giving you a hint.
use this call in the program.
"system()"Wednesday, June 6, 2007 4:52 PM
All replies

Yup start asking the questions...Tuesday, May 29, 2007 12:43 PM

arre yaar.
why don't you post problems here?
let me also solve them.
& side by side i'll also post questionsTuesday, May 29, 2007 3:10 PM 
Ok, i have a nice one for you....
write a program which gives the Nth largest number from an array.. the array is not in sorted form.. but you have to do it without sorting the array....Tuesday, May 29, 2007 3:57 PM 
//let arr[size] be the array
void main()
{
int n_larg,i,j,index;
printf("enter the number of the largest number which you find to find\n");
scanf("%d",&n_larg);
for(i=1 ; i<=n_larg ; i++)
{
n_larg=arr[0];
index=0;
for(j=0;j<size;j++)
if(n_larg<arr[j])
{ n_larg=arr[j]; index=j;}
if(i!=n_larg)
arr[index]=0;
}
printf("the %dth largest number is %d at an index %d",n_larg,arr[index] , index);
}Wednesday, May 30, 2007 2:01 AM 
The code is having problems.. try to run it.. i ran it and it had problems... I will post my code.. have a look at it..
// This program will find the Kth smallest number from the list without sorting.
#include<stdio.h>
#include<conio.h>
void main()
{
int data[30], i, j, n, k, temp=30000, min;
printf("Please give the number of entries in the series : ");
scanf("%d",&n);
printf("Please give the data :\n");
for(i=0;i<n;i++)
scanf("%d",&data[i]);
printf("Please give the value of K (the Kth smallest number) : ");
scanf("%d",&k);
for(j=k; j>0; j)
{
min=30000;
for(i=0; i<n; i++)
{
if (data[i]<min && data[i]>temp)
min=data[i];
}
temp = min;
}
printf("The %d Smallest Number = %d", k,temp);
getch();
}
This program is for the smallest one.. you can create one for the greatest one from thisWednesday, May 30, 2007 4:51 AM 
well, my code is running well here.
which problems have you encountered?
& after looking at your code, our logics seem to be pretty same.
& if i'm right then say it
&
post another query hereWednesday, May 30, 2007 4:57 AM 
sorry small mistake.
//let arr[size] be the array
void main()
{
int n_larg,i,j,index,lar;
printf("enter the number of the largest number which you find to find\n");
scanf("%d",&n_larg);
for(i=1 ; i<=n_larg ; i++)
{
lar=arr[0];
index=0;
for(j=0;j<size;j++)
if(lar<arr[j])
{ lar=arr[j]; index=j;}
if(i!=n_larg)
arr[index]=0;
}
printf("the %dth largest number is %d at an index %d",n_larg,arr[index] , index+1);
}
check it nowWednesday, May 30, 2007 5:08 AM 
Yup its working fine... good....
Now answer this... write a code to create a series like this....
111
112
113
121
122
123
131
132
133
211
212
.................
332
333
This is the case of generating all the permutation of N numbers.. like we have 3 above and the possible set of 3 numbers is generated, like 1 1 1 is one set 1 2 3 is another set...
So you take 2 input
1) the number N
2) The size of the set K....Wednesday, May 30, 2007 7:14 AM 
well, this can be done using nested loops technique.
here's a new problem.
IMPLEMENT star topology using C.Monday, June 4, 2007 2:46 AM 
What is a star topology???Monday, June 4, 2007 6:33 AM

it's a network topology.
haven't you studied networking?Monday, June 4, 2007 6:37 AM 
Nope, m still in 2nd sem, will be studying networking in 4th sem...Monday, June 4, 2007 7:53 AM

ok.
so i have to give you another problem.
here it is.
write a program which will take input string from user & list it's contents files, subdirectories, children sub directories.
for e.g.
let we have a folder named sunil in d:/
this folder contains the following folders.
folders within sunil files/folders within each folder
sameer file1, sayhello, .....
varun ............
harshil ...........
& files :
program
then program should output:
sameer
file1,sayhello
varun
..........,.......
harshil
..........,............
programMonday, June 4, 2007 11:12 AM 
it's easy.
i'm giving you a hint.
use this call in the program.
"system()"Wednesday, June 6, 2007 4:52 PM