Concept Challenge - TechSho

Post Top Ad

Responsive Ads Here

1.Array – Sum of Even Numbers 


Write a program to find the sum of the even numbers present in an array using recursion.

Input and Output Format:

Refer sample input and output for formatting specifications.

[All text in bold corresponds to the input and the rest corresponds to output]

Sample Input and Output:

Enter the number of elements in the array

4

Enter the elements in the array

23

54

67

98

The sum of the even elements in the array is 152


CODE:
#include<stdio.h>
void SumOfEven(int a[],int num,int sum);
main()
{
    int i,a[100],num,sum=0;
    printf("Enter number of Array Elements\n");
   scanf("%d",&num);
   printf("Enter Array Elements\n");
   for(i=0;i<num;i++)
   {
    scanf("%d",&a[i]);
    }
   SumOfEven(a,num-1,sum); 
}

void SumOfEven(int a[],int num,int sum)
{
 
 if(num>=0)
 {
  if((a[num])%2==0)
  {
   sum+=(a[num]); 
  }
  SumOfEven(a,num-1,sum);
 }
 else
 {
    printf("Sum=%d\n",sum); 
  return;
 }
}


2. Given a requirement, partially correct program and set of inputs, mark the input for which the program will not function as expected in the requirement.
Surprise Awards

Bishop Cotton High School was celebrating as the school’s Grade 10 students have come out with flying colours in their Board Exams. The School management was overwhelmed by the outperforming achievement of the students and organised for a celebration to honour the top scorers. Too many students have procured 100 on 100 in all the subjects. Hence, at the celebrations, the management presented the proficiency certificate for all of the top scorers and centum scorers.
The management also wanted to provide surprise awards to few students. Those few students are selected based on their roll numbers. The criterion applied on the roll numbers is the concept of lucky numbers. Lucky numbers are those positive numbers whose decimal representation contains only the digits 4 and 7. Almost lucky roll numbers are taken into consideration for award giving and they are considered as numbers that could be evenly divided some lucky number.
For example, numbers  47,  744,  4 are lucky and  5,  17,  467 are not.

Let us write a program to find out if the given roll number is almost lucky or not.

Input and Output Format:

The input consists of a single integer n (1 ≤ n ≤ 1000) — the number that needs to be checked.

The output prints "YES" (without the quotes), if number n is almost lucky. Otherwise, print "NO" (without the quotes).

Sample Input and Output 1:
Enter the number
47
YES

Sample Input and Output 2:
Enter the number
16
YES

Sample Input and Output 3:
Enter the number
78
NO



3. Find the output of the following program

#include<stdio.h>
int main()
{
    int a[100],i,mycap=1,h,count=0;
    for(i=0;i<=a[0]+1;i++)
    scanf("%d",&a[i]);
    
    h=a[0]+1;
    for(i=1;i<=a[0];i++)
    {
    ;
    if(a[i]<=mycap)
    {
        mycap=a[i]+a[h];
        count++;
    }
    else
    break;
}
printf("%d",count);
return 0;
}

Input:
7
1
12
23
35
50
75
90
16

Output:
5

Thank you. If you have any doubt please ask in the comment section.

No comments:

Post a Comment

Post Bottom Ad

Responsive Ads Here

Pages