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   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
Write a C function to search a number in the given list of 
numbers. donot use printf and scanf
 Question Submitted By :: Nazim
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Write a C function to search a number in the given list of numbers. donot use printf and scanf
Answer
# 1
#include<stdio.h>
#include<conio.h>
void main()
{
char a[]="enter the no. of terms tou are going to enter :";
char a1[100];
char n;
puts(a);
int flag=0;
n=getchar();
int n1;
n1=(int)n    /* type casting*/
   for(int i=0;i<n1;i++)
      {
    a[i]=getchar();
}
char a3[]="enter the number do you want to find :";
puts(a3);
char s;
  s=getchar();
int b=(int)s;
  for(i=0;i<n1;i++)
{
     if(b==(int)a[i])
flag=1;
   }
if(flag==1)
printf("number is found");
else 
printf("not found");
getch();
}
this was the logic suddenly striked me.......................
 
Is This Answer Correct ?    1 Yes 0 No
Vignesh1988i
 
  Re: Write a C function to search a number in the given list of numbers. donot use printf and scanf
Answer
# 2
very sorry yaar/.... i forgettenly used printf statements in
my before posts.......... i think this can be the logic...
if am not wrong..............

#include<stdio.h>
#include<conio.h>
void main()
{
char a[]="enter the no. of terms tou are going to enter :";
char a1[100];
char n;
puts(a);
int flag=0;
n=getchar();
int n1;
n1=(int)n    /* type casting*/
   for(int i=0;i<n1;i++)
      {
    a[i]=getchar();
}
char a3[]="enter the number do you want to find :";
puts(a3);
char s;
  s=getchar();
int b=(int)s;
  for(i=0;i<n1;i++)
{
     if(b==(int)a[i])
flag=1;
   }
if(flag==1)
{
char q[]="number is found";
puts(q);
}
else
{
char w[]="number not found";
puts(w);
}
getch();
}
 
Is This Answer Correct ?    0 Yes 0 No
Vignesh1988i
 
 
 
  Re: Write a C function to search a number in the given list of numbers. donot use printf and scanf
Answer
# 3
Dear... Vignesh... r u tested?
if tested..., on what Compiler...
 
Is This Answer Correct ?    0 Yes 0 No
Gg
 
  Re: Write a C function to search a number in the given list of numbers. donot use printf and scanf
Answer
# 4
ya..... sorry... it wont work... since getchar gets only one
character the time.... when we give 48... i will take 4 and
8 .. but not as 48.... sorry for posting it... a lesson i
have learnt
 
Is This Answer Correct ?    0 Yes 0 No
Vignesh1988i
 
  Re: Write a C function to search a number in the given list of numbers. donot use printf and scanf
Answer
# 5
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main ( int argc, char* argv[] )
{
	int array [ 10 ] = { 546, 541, 128, 1027, 1000, 
10234, 657, 343, 111, 272 };
	char _variable [ 50 ];
	int _count = 0;
	int _value = 0;

	memset ( _variable, '\0', 50 );
	puts ("Enter the number to search: ");
	gets ( _variable );
	
	_value = atoi ( _variable );

	for ( _count = 0; _count < 10; _count++ ) {
		if ( array [ _count ] == _value ) {
			puts ("Search SUCCESSFUL");
			return ( 0 );
		}
	}
	puts ("Search NOT SUCCESSFUL");
	return ( 1 );
}

If u guys really want to check the given input is numeric, 
use isnumeric function defined in ctypes.h
 
Is This Answer Correct ?    0 Yes 0 No
Abdur Rab
 
  Re: Write a C function to search a number in the given list of numbers. donot use printf and scanf
Answer
# 6
sorry for the wrong information use isdigit(char)
 
Is This Answer Correct ?    0 Yes 0 No
Abdur
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
How can I allocate arrays or structures bigger than 64K?  4
how many times does the loop iterated ? for (i=0;i=10;i+=2) printf("Hi\n"); TCS6
how can i make a program with this kind of output.. Enter a number: 5 0 01 012 0123 01234 012345 01234 0123 012 01 0 Wipro2
What's wrong with the call "fopen ("c:\newdir\file.dat", "r")"?  1
how to do in place reversal of a linked list(singly or doubly)?  1
Study the code: void show() main() { show(); } void show (char *s) { printf("%sn",s); } What will happen if it is compiled & run on an ANSI C Compiler? A)It will compile & nothing will be printed when it is executed B)it will compile but not link C)the compiler will generate an error D)the compiler will generate a warning Accenture3
AMMONG THE 4 STROAGE CLASSES IN C, WHICH ONE FASTEST? HCL9
how to find sum of digits in C? CTS8
Program to find the value of e raised to power x using while loop N-Tech3
I have a function which accepts a pointer to an int. How can I pass a constant like 5 to it?  3
Concat two string with most overlapped substring has to remove  "abcd"+ "cdef" = "abcdef  5
What's the difference between a linked list and an array?  8
1.what are local and global variables? 2.what is the scope of static variables? 3.what is the difference between static and global variables? 4.what are volatile variables? 5.what is the use of 'auto' keyword? 6.how do we make a global variable accessible across files? Explain the extern keyword? 7.what is a function prototype? 8.what does keyword 'extern' mean in a function declaration?  1
#include<stdio.h> main() { char s1[]="Ramco"; char s2[]="Systems"; s1=s2; printf("%s",s1); } Find the output CitiGroup4
52.write a “Hello World” program in “c” without using a semicolon? 53.Give a method to count the number of ones in a 32 bit number? 54.write a program that print itself even if the source file is deleted? 55.Given an unsigned integer, find if the number is power of 2?  4
9.how do you write a function that takes a variable number of arguments? What is the prototype of printf () function? 10.How do you access command-line arguments? 11.what does ‘#include<stdio.h>’ mean? 12.what is the difference between #include<> and #include”…”? 13.what are # pragma staments? 14.what is the most appropriate way to write a multi-statement macro? L&T4
main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); } ME3
main() { int x=5; printf("%d %d %d\n",x,x<<2,x>>2); } CitiGroup3
What do you mean by team??  2
what is the difference between const volatile int i & volatile const int j; HCL1
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
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