Index-1              Index-2              Home Page

Array programming


Write a C Program to fill up an Integer Array. The length of the array must take from the terminal. After fill up the array do the following operations.
i)                    Print the array with label formatting.
ii)                   Count the number of values inside the array.
iii)                 Count the number of odd values.
iv)                 Count the number of even values.
v)                  Sum all the odd values.
vi)                 Sum all the even values.
vii)               Calculate the average.
viii)              Find the largest value.
ix)                 Find the smallest value.


<< Go to Index Page >>

20 comments:

  1. I have written a code of this program. The code is too long. This frame is unable to show the code at a time.

    ReplyDelete
  2. you can write main body as accepted as here...

    ReplyDelete
  3. #include
    main()
    {
    int i, a[10],value,count=0,sum1=0,sum2=0,max=0,min=32678;
    float avg=0,sum=0;
    printf("Enter your enteger value:\n");
    for(i=0;i<10;i++)
    {
    scanf("%d",&value);
    a[i]=value;
    printf("[%d]=%d\n",i,a[i]);
    }
    for(i=0;i<10;i++)
    {
    count+=a[i];
    }
    printf("\n Sum inside array number:%d",count);
    for(i=0;i<10;i++)
    {
    if(a[i]%2==0)
    {
    printf("\n\n Even numberis:%d",a[i]);
    }
    }
    for(i=0;i<10;i++)
    {
    if(a[i]%2!=0)
    {
    printf("\n\n Odd numberis:%d",a[i]);
    }
    }
    for(i=0;i<10;i++)
    {
    if(a[i]%2==0)
    {
    sum1+=a[i];
    }
    }
    printf("\n Sum of even number:%d",sum1);
    for(i=0;i<10;i++)
    {
    if(a[i]%2!=0)
    {
    sum2+=a[i];
    }
    }
    printf("\n sum of Odd number:%d",sum2);
    for(i=0;i<10;i++)
    {
    sum+=a[i];
    }
    avg=sum/10;
    printf("\n avg=%.2f",avg);
    for(i=0;i<10;i++)
    {
    if(a[i]>max)
    {
    max=a[i];
    }
    }
    printf("\nLargest value:%d",max);
    for(i=0;i<10;i++)
    {
    if(a[i]<min)
    {
    min=a[i];
    }
    }
    printf("\nsmallest value:%d",min);
    getch();

    ReplyDelete
  4. #include
    main()
    {
    int len,i,ceven=0,codd=0,evensum=0,oddsum=0,lar,sma;
    float avg=0;
    printf("Enter the size of the Array\n");
    scanf("%d",&len);
    int a[len];
    printf("Enter %d values for array\n",len);
    for(i=0;ilar)
    {
    lar=a[i];
    }
    }
    for(i=0;i<len;i++)
    {
    if (a[i]<sma)
    {
    sma=a[i];
    }
    }
    printf("\nThe largest element is: %d",lar);
    printf("\nThe smallest element is: %d",sma);
    }

    ReplyDelete
  5. #include
    #define MAX 20
    #define AXE 20
    main()
    {
    int c,d,sum1=0,sum2=0,temp=0,count=0,i,n,count1=0,j;
    int a[MAX];
    printf("Enter the array size: ");
    scanf("%d",&n);
    for(i = 0; i < n; i++)
    {
    printf("\n Enter %d value: ",i+1);
    scanf("\n %d", &a[i]);
    }
    int max = a[0];
    int min = a[0];

    for (i = 0; i max)
    {
    max = a[i];
    }
    else if (a[i] < min)
    {
    min = a[i];
    }
    }
    printf("\nArray Values: ");
    for(i = 0; i < n; i++)
    {
    printf("%3d ",a[i]);
    temp+=a[i];
    if(a[i]%2==0)
    {
    count++;
    sum1+=a[i];
    }
    else
    count1++;
    sum2=temp-sum1;
    }
    float b=temp/n;
    printf ("\nMaximum element in an array : %d\n", max);
    printf ("\nMinimum element in an array : %d\n", min);
    printf("\nthe avarage value of array is:%0.3f\n",b);
    printf("\nThe sum of array is:%d\n",temp);
    printf("\nThe number of even is:%d\n",count);
    printf("\nThe number of odd is:%d\n",count1);
    printf("\nThe sum of even is:%d\n",sum1);
    printf("\nThe sum of odd is:%d\n",sum2);
    }

    ReplyDelete
  6. Summer 2017
    ID#201610042

    Answer to the Question No 4:

    https://drive.google.com/file/d/0B99eePh0LV8gRWdBdEVXblR0UTA/view?usp=drivesdk

    ReplyDelete
  7. ID : 201620195
    https://drive.google.com/open?id=0B9K31ospCyFjQnIxa0UwMXpFOFU

    ReplyDelete
  8. ID:201520552
    https://drive.google.com/open?id=0B5pG0kIjzgEKYUdNZlZqREltMnM

    ReplyDelete
  9. ID 201610456
    MD USUF MIA
    https://drive.google.com/open?id=0B_PIGnOMR0K2Qy00VGFEZFlRY0E

    ReplyDelete
  10. https://drive.google.com/open?id=0Byxq3aat_mNSRWNMUFQyaTZER1U

    ReplyDelete
  11. ID: 201620318
    https://drive.google.com/open?id=0B2gcteJZycWod1Nzcm5USm5tYWs

    ReplyDelete
  12. https://drive.google.com/open?id=0B3bVD5Ppt_STek5zTjVXckNDM2s

    ReplyDelete
  13. Nusrat Sumaiya AshrafeJune 8, 2017 at 8:34 AM

    ID: 201710950
    https://drive.google.com/open?id=0B1SMDOPeCkX_QWVXQjFnQURSM3c

    ReplyDelete
  14. ID:201610254


    #include
    using namespace std;

    class arr
    {
    public:
    int a[30],n,i,odd,even,sumodd,sumeven,larg,small,sum;
    float ave;
    void arrprint()
    {
    cout<<"Enter array srize:";
    cin>>n;
    for(i=0;i>a[i];

    cout<<"i)Print the array with label formatting:"<a[i])
    {
    small=a[i];
    }
    }
    cout<<small<<endl<<endl;



    }
    };
    int main()
    {
    arr obj;
    obj.arrprint();

    return 0;
    }

    ReplyDelete
  15. Id: 201820244
    Batch:58th
    section:B
    #include
    int main()

    {
    int i;
    int a[10]={1,2,3,4,5,6,7,8,9,10};
    float sum=0;
    float average=0;
    int max=0,min=a[0];
    int odd,even;
    printf("Enter no: ");
    for(i=0;i<5;i++){


    scanf("%d",&a[i]);

    sum+=a[i];

    }

    for(i=0;i<5;i++){

    if(a[i]%2==0)

    printf("even: %d",even);

    if(a[i]%2==1)

    printf("odd: %d",odd);

    }

    for(i=0;i<5;i++){

    if(a[i]>max){

    max=a[i];

    }

    else if(a[i]<=min){

    min=a[i];

    }

    }

    printf("max: %d\n",max);

    printf("min: %d\n",min);

    printf("sum: %.1f",sum);

    average=sum/10;

    printf("average: %1.f",average);



    return 0;

    }

    ReplyDelete
  16. ID#201830546

    #include
    using namespace std;
    main()
    {
    int c,d,sum1=0,sum2=0,temp=0,count=0,i,n,count1=0,j;
    int a[MAX];
    cout<< "Enter the array size: ";
    cin>>n;
    for(i = 0; i < n; i++)
    {
    cout<< “Enter value: ", i+1;
    cin>>a[i];
    }
    int max = a[0];
    int min = a[0];

    for (i = 0; i max)
    {
    max = a[i];
    }
    else if (a[i] < min)
    {
    min = a[i];
    }
    }
    cout<< “Array Values: ";
    for(i = 0; i < n; i++)
    {
    cout<<a[i];
    temp+=a[i];
    if(a[i]%2==0)
    {
    count++;
    sum1+=a[i];
    }
    else
    count1++;
    sum2=temp-sum1;
    }
    float b=temp/n;
    cout<< "Maximum element in an array : ", max<<endl;
    cout<< "Minimum element in an array :", min<<endl;
    cout<<"the average value of array is:", b<<endl;
    cout<<"The sum of array is:", temp<<endl;
    cout<<"The number of even is:", count<<endl;
    cout<<"The number of odd is:", count1<<endl;
    cout<<"The sum of even is:", sum1<<endl;
    cout<<"The sum of odd is:", sum2<<endl;
    }

    ReplyDelete
  17. Name : Firoj Ahmed
    ID : 201820222
    Batch : 58th

    #include
    #include
    using namespace std;

    class array
    {
    int *p, c_full, c_odd, c_even, sum_odd, sum_even, max, min;

    float avg;

    public:

    array(int x)
    {
    p=(int*) malloc(x*sizeof(int));
    c_full=x;
    c_odd=c_even=sum_odd=sum_even=0;
    }

    void input(void)
    {
    cout<<"Enter "<>p[i];
    }
    }

    void count (void);
    void print (void);
    };

    int main()
    {
    int n;

    cout<<"Enter length of the Array: ";
    cin>>n;

    array obj(n);

    obj.input();
    obj.count();
    obj.print();

    return 0;
    }

    void array::count(void)
    {
    min=max=p[0];

    for (int i=0; ip[i])
    min=p[i];
    }

    avg = (sum_odd+sum_even)/(float) c_full;
    }

    void array::print (void)
    {
    cout<<"\n\nThe values present in the array is:"<<endl;
    for (int i=0; i<c_full; i++)
    {
    cout<<p[i]<<" ";
    }
    cout<<'\n';
    cout<<"Total values in the array= "<<c_full<<endl;
    cout<<"Number of Odd values= "<<c_odd<<endl;
    cout<<"Number of Even values= "<<c_even<<endl;
    cout<<"Summation of the odd values= "<<sum_odd<<endl;
    cout<<"Summation of the even values= "<<sum_even<<endl;
    cout<<"Average= "<<avg<<endl;
    cout<<"Maximum value in array= "<<max<<endl;
    cout<<"Minimum value in array= "<<min<<endl;
    }

    ReplyDelete
  18. ID:201810461
    //overloading//
    #include
    using namespace std;
    void display(int);
    void display(float);
    void display(int,float);
    int main()
    {
    int a = 5;
    float b = 5.5;

    display(a);
    display(b);
    display(a, b);

    return 0;
    }
    void display(int var)
    {
    cout <<"Integer number:" << var << end1;
    }
    void display(float var)
    {
    cout << "float number:" <<var << end1;
    }
    void display(int var1, float var2)
    {
    cout << "integer number:" <<var1;
    cout << "and float number:" <<var2;
    }

    ReplyDelete
  19. ID:201810461
    //Array program using inheritance//
    #include
    using namespace std;
    class Habibur Rahman
    {public:
    for (i=o ; i<5 ; i++)

    };
    class B : public Habibur Rahman
    int foo [] = {16, 2, 77};
    int i, result=0;

    int main(){

    {
    result +=foo[i];
    }
    cout << result;
    return();
    }

    ReplyDelete
  20. ID#201830546

    #include
    using namespace std;
    class array_man
    {
    public:
    int i,n=5,sum=0,sum1=0,sum2=0,a[5];

    array_man()
    {
    for (i=0;i> a[i];
    }
    int array_sum()
    {
    for (i=0;i<n;i++)
    sum+=a[i];
    return sum;
    }
    void evenodd_sum()
    {
    for(i=0;i<n;i++)
    {
    if(a[i]%2==0)
    sum1=sum1+a[i];
    else
    sum2=sum2+a[i];
    }
    }
    ~array_man()
    {
    }
    };

    int main()
    {
    array_man obj;
    cout <<obj.array_sum()<<endl;
    obj.evenodd_sum();
    cout <<obj.sum1<<endl;
    cout<<obj.sum2<<endl;
    }

    ReplyDelete