/* C program: print a sub-array b of size k that have mean m from a given array a of size n. Description: Question asked in written (codding) test of FactSet recruitment drive at NIT Durgapur Campus on September 14, 2016. Example 1: int a[] = {1,2,3,4,5,6,7,8,9,0}, k = 4, m = 6 then b will be b[] = {7,8,9,0} and should print 7 8 9 0 Compiler: GNU GCC v4.8.3 Author: Mangilal Sharma (with Ramesh Kumar Thakur) Date: September 15, 2015 Program for: world-of-c-programming.blogpost.com Program number: 103 */ #include <stdio.h> #define SIZE 20 void findMeanSubarray(int a[], int k, int m, int n); int main() { int a[] = {1,2,3,4,5,6,7,8,9,0}, k = 4, m = 6; int n = sizeof(a)/sizeof(a[0]); findMeanSubarray(a,k,m,n); return 0; }//Only the following function code required to write in test.
void findMeanSubarray(int a[], int k, int m, int n)
{
int b[SIZE], i, j, flag = 0, sum;
for(i=0;i<=n-k+1;i++)
{
sum=0;
for(j=0;j<k;j++) sum+= a[i+j];
if(sum == m*k) break;
}
if(i<=n-k) for(j=i;j<i+k;j++) printf("%d\t",a[j]);
else printf("Has not found any required subarray in given array.\n");
}
You can test program on this online c editor & compiler:
http://www.tutorialspoint.com/compile_c_online.php
{
int b[SIZE], i, j, flag = 0, sum;
for(i=0;i<=n-k+1;i++)
{
sum=0;
for(j=0;j<k;j++) sum+= a[i+j];
if(sum == m*k) break;
}
if(i<=n-k) for(j=i;j<i+k;j++) printf("%d\t",a[j]);
else printf("Has not found any required subarray in given array.\n");
}
thanks for creating a nice post on c programming but did you know what is loop in c programming
ReplyDeleteThanks for sharing your knowledge. It's very useful for all. Keep sharing. c programming classes in pune
ReplyDeleteVery Useful Post!Thanks!
ReplyDeleteC Programming
Good and informative article. . I refer https://mettl.com/ and this is best site I found for C programming .
ReplyDeleteShadow Paging Technique
ReplyDeleteAnalysis and Synthesis Phases
Moore Machine
Peephole Optimization
Block Structure | Non-Block Structure
Address Sequencing
Classification Memory
Hamiltonian Problem
One-pass Macro Processors
very nice..post.
ReplyDeletehttps://shayarihindishayari.com/
nice
ReplyDeleteYour article is really worth reading. I've been following your blogs for a while and you are doing a great job.
ReplyDeletewatch C# Full course
watch Java Programming Full course
watch SQL Tutorial for beginners
watch Python tutorial
watch SQL Database Full course
Hack Netflix account. now use Neflix account free for always.click to follow simple steps
ReplyDeleteGuaranteed Success.
Hack Netflix Account
Nice..
ReplyDeletefinal year project proposal for information technology
free internship for bca
web designing training in chennai
internship in coimbatore for ece
machine learning internship in chennai
6 months training with stipend in chennai
final year project for it
inplant training in chennai for ece students
industrial training report for electronics and communication
inplant training certificate
Good Post...
ReplyDeletesnowflake interview questions and answers
inline view in sql server
a watch was sold at loss of 10
resume format for fresher lecturer in engineering college doc
qdxm:sfyn::uioz:
java developer resume 6 years experience
please explain in brief why you consider yourself suitable for the position applied for
windows 10 french iso kickass
max int javascript
tp link router password hack