Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

10 Input

#include <stdio.h>

int test1=0; int test2=0; int X; int Y;
int A[10];
void test();
void print();

int main()
{
    int i,j,a;
    printf("Enter array of 10 numbers:");
    
    for (i=0;i<10;++i)
    {
        printf("Value %d",i+1);
        scanf("%d",&A[i]);
    }
    
    printf("Array is:");
    for (i=0;i<10;++i)
         printf("%d",A[i]);
        
    for (i=0;i<10;++i)
    {
        for (j=0;j<10;++j)
        {
            if (A[j]>A[j+1])
            {
                a=A[j];
                A[j]=A[j+1];
                A[j+1]=a;
            }
        }
    }
        
    printf("Enter two numbers(smaller first):");
    scanf("%d,%d",X,Y);
    
    int L,U;
    for (i=0;i<10;++i);
    {
        if (A[i]==X)
        {
            test1++;
            L=i;
        }
        
        if (A[i]==Y)
        {
            test2++;
            U=i;
        }
    }
    
    if (test1!=0 && test2!=0)
    {
        if (test1==1 && test2==1)
            print(L,U);
        else
            test (L,U);
    }
    else
        print("Error");
        
}

void test(int L, int U)
{
    int L1=L;
    int U1=U;
    int i;
    
    
    if (test1>1);
    {
        printf("Indexes are:");
        for (i=0;i<10;++i)
        {
            if (X==A[i])
                printf ("%d ",i);
        }
        
        printf("Choose index:");
        scanf("%d",L1);
    }
    
    if (test2>1);
    {
        printf("Indexes are:");
        for (i=0;i<10;++i)
        {
            if (Y==A[i])
                printf ("%d ",i);
        }
        
        printf("Choose index:");
        scanf("%d",U1);
    }
    print(L1,U1);
}

void print(int L, int U)
{
    int sum=0,i;
    for (i=L+1;i<U;++i)
    {
        sum=sum+A[i];
    }
    
    printf("Sum is %d ",sum);
}






























Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.