Answer to Question #274112 in C for Vishal

Question #274112

John is going through his family photo album. There is a total of people in the family labeled from 0 to N-1.






Find out the number of members of his family who have more than equal to X children.






Input Specification:






input1: N. denoting the total number of family members.




input2: X denoting the minimum number of children a family member should have in order to be included in John's final set.




input3: An array of N elements where the ith element denotes the parent of the ith index. If the value of the element is -1, then that family member has no parent.






Output Specification:






Your function should return the number of John's family members that have more than or equal to X childrens.






Example 1:






Input1: 1




input2:0




input3:{-1}






output:1






Explanation :Family member 0 has 0 children. As we have to return the family membersthat have more than or equal to 0 children.hence the answer is 1.

1
Expert's answer
2021-12-02T00:38:03-0500
#include<stdio.h>
int main(){
	int N ;
	scanf("%d", &N);
		int X ;
		scanf("%d", &X);
		int Parent[N] ;
		
		int sub[N] ;
		
		int c = 0;
		int i =0;
		for( i=0; i<N; ++i)
		{
			scanf("%d", &Parent[i]);
			
			
			if(Parent[i] != -1)
				++sub[Parent[i]];
		}
		i = 0;
		for(i=0; i<N; ++i)
		{
			if(sub[i] >= X)
				++c;
		}
		
		printf("%d", c);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS