Write a program using one dimensional array that searches a
number and display the number of times it occurs on the list
of 12 input values.
Sample input/output dialogue:
Enter 12 values:
13 15 20 13 30 35 40 16 18 20 18 20
Enter number to search: 20
Occurences: 3

Answers were Sorted based on User's Feedback



Write a program using one dimensional array that searches a number and display the number of times ..

Answer / naveen kumar

change the sizeof array a[12] instead of a[4]

Is This Answer Correct ?    7 Yes 15 No

Write a program using one dimensional array that searches a number and display the number of times ..

Answer / sreejesh1987

#include<stdio.h>
#include<conio.h>
void main()
{
int i,flag=0;
float s,a[4];
clrscr();
printf("Enter Twelve numbers:");
for(i=0;i<12;i++)
scanf("%f",&a[i]);

printf("Enter a number to search:");
scanf("%f",&s);

for(i=0;i<12;i++)
if(a[i]==s)
flag++;


printf("\nOccurances:%d",flag);

getch();
}

Is This Answer Correct ?    16 Yes 32 No

Post New Answer

More C++ Code Interview Questions

void main() { int i,j=2; for(i=0;i<3;i++) if(j=i) cout<<"Lotus "; else cout<<"Rose "; } Its result is Rose Lotus Lotus.. How? Explain it?

2 Answers  


Assume in University Every student in university as entity, prepare a class for student that store the roll no, name, dob of student, and make funtion of deletion, manipulation, addition of student record.

0 Answers  


write a program that reverses the input number of n.Formulate an equation to come up with the answer.

0 Answers   Satyam,


Write a &#61521;(n) algorithm that sorts n distinct integers, ranging in size between 1 and kn inclusive, where k is a constant positive integer. (Hint: Use a kn-element array.)

0 Answers  


write a program to calculate the amount of investment after a period n years if the principal investors was p and interest is calculated using compound interest,formular=a=p(1+r)^n

0 Answers   Jomo Kenyatta University,






find level of following tree (state, parent) " J,D I,D H,C E,B F,B G,C B,A D,A C,A A,& K,E L,E L,F M,F N,G O,H P,I P,H Q,I R,J S,K U,P T,L

0 Answers  


what is the use of using for loop as "for(;;)"?

5 Answers   Satyam,


write a c program, using for loop, that accepts and odds two numbers. The output must be the sum and the addens. This should be repeated 5 times while the first number is decremented by one and the second number is incremented by 1.

2 Answers   IBM, Infosys,


write a program that can locate elements in array.

1 Answers  


can you please write a program for deadlock that can detect deadlock and to prevent deadlock.

0 Answers  


what mean void creat_object?in public class in this code class A{ public: int x; A(){ cout << endl<< "Constructor A";} ~A(){ cout << endl<< "Destructor A, x is\t"<< x;} }; void create_object(); void main() { A a; a.x=10; { A c; c.x=20; } create_object(); } void create_object() { A b; b.x=30; }

0 Answers  


can we declare an object of a class in another class?(assume both class as public classes)

1 Answers   Microsoft,


Categories