Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to find 3 sequential numbers that have the biggest sum form input of 15 numbers in C

1 Answer

0 votes
#include <stdio.h> 

int main(void)
{
    int mx1, mx2, mx3, n1, n2, i, nw;
    
    printf("Enter a number: ");
    scanf("%d", &mx1);
    
    printf("Enter the next number: ");
    scanf("%d", &mx2);
    
    printf("Enter the next number: ");
    scanf("%d", &mx3);
    
    printf("Enter the next number: ");
    scanf("%d", &nw);

    n1 = mx2; n2 = mx3;
    i = 4;
    
    while (i < 15)
    {
        if (n1 + n2 + nw > mx1 + mx2 + mx3)
        {
            mx1 = n1;
            mx2 = n2;
            mx3 = nw;
        }
        n1 = n2;
        n2 = nw;
        
        printf("Enter the next number: ");
        scanf("%d", &nw);
        i++;
    }
    printf("3 max numbers sequence: %d %d %d\n", mx1, mx2, mx3);
            
    return 0;
}


/* 
run:

Enter a number: 1
Enter the next number: 4
Enter the next number: 900
Enter the next number: 3
Enter the next number: 100
Enter the next number: 300
Enter the next number: 20
Enter the next number: 50
Enter the next number: 100
Enter the next number: 5
Enter the next number: 500
Enter the next number: 5
Enter the next number: 200
Enter the next number: 13
Enter the next number: 70
3 max numbers sequence: 900 3 100

*/




answered Sep 17, 2014 by avibootz
...