Question

In: Computer Science

Write program to store ten integers in an array and the program will do the following...

Write program to store ten integers in an array and the program will do the
following
Find the average of even marks

Find how many prime integers inserted
Note: please solve it by c , not c++

Solutions

Expert Solution


#include <stdio.h>

int prime(int arr[])
{
    int i,j,count,k;
    count=0;
    for(i=0;i<10;i++)
    {
        k=0;
        for(j=1;j<=arr[i];j++)
        {
            //counting the number of factors for the array element
            if(arr[i]%j==0)
            {
                k++;
            }
        }
        //if the no of factor is equal to 2 
        //it will count it as prime
        if(k==2)
        {
            count++;
        }
    }
    //returning the number of prime numbers
    return count;
}
int main()
{
    int arr[10];
    int i,count,sum;
    //taking the array inputs
    printf("Enter ten array elements of integer type .\n");
    for(i=0;i<10;i++)
    {
        scanf("%d",&arr[i]);
    }
    sum=count=0;
    //calculating sum for the array index of even positions
    for(i=0;i<10;i=i+2)
    {
        sum=sum+arr[i];
        count++;
    }
    //printing the corresponding average
    printf("The average of the even marks : %d\n",(sum/count));
    sum=count=0;
    //calculating sum for the array elements which are even
    for(i=0;i<10;i++)
    {
        if(arr[i]%2==0)
        {
            sum=sum+arr[i];
            count++;
        }
    }
    //printing the corresponding average
    printf("The average of the even numbers : %d\n",(sum/count));
    //calling the function to count
    //the number of prime present in the array
    count=prime(arr);
    printf("The number of prime numbers present in the array is : %d\n",count);
    return 0;
}

Related Solutions

Write a program in Java that initializes an array with ten random integers and then print...
Write a program in Java that initializes an array with ten random integers and then print three lines of output, containing: Every element at an odd index Every odd element All elements in reverse order   The program should use three different methods to implement the functionalities above. Call the primary source file ArrayManipulator.java
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers...
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers as follows: Assign {35,20,-43,-10,6,7,13} -Create a one dimensional array of 7 Boolean values as follows: Assign {true,false,false,true,false,true,false} -Create a one dimensional array of 7 floating-point values as follows: Assign {12.0f,1.5f,-3.5f,-2.54f,3.4f,45.34f,22.13f} -Declare sum as integer and set it to 0. -Declare sumf as float and set it to 0.0f. -Use a for loop to go through each element of the Boolean array, and if an...
*****IN JAVA***** Write a code snippet that initializes an array with ten random integers and then...
*****IN JAVA***** Write a code snippet that initializes an array with ten random integers and then prints the following output: a. every element (on a single line) b. every element at an even index (on a single line) c. every even element (on a single line) d. all elements in reverse order (on a single line) e. only the first and last elements (on a single line)
write a program which will prompt an array of 12 integers then print the array as...
write a program which will prompt an array of 12 integers then print the array as an array of 4 columns on 3 rows
Write a Java program that reads a list of integers into an array. The program should...
Write a Java program that reads a list of integers into an array. The program should read this array from the file “input.txt”. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is a two-column list. The first column is the list of the distinct array elements; the second column is the number of occurrences of each element. The list should be sorted on entries in...
write a c++ program to perform the following operations on stack of Integers (Array Implementation of...
write a c++ program to perform the following operations on stack of Integers (Array Implementation of Stack with maximum size MAX) (i) Push an Element on to stack (ii) Pop an Element from stack (iii) Demonstrate how stack can be used to check Palindrome (iv) Display the status of stack (v) Exit
Write a program that does the following: Generate an array of 20 random integers between -100...
Write a program that does the following: Generate an array of 20 random integers between -100 and 100. Compute the average of the elements of the array and find the number of elements which are above the average. For example, if the elements of the array were 5 2 4 1 3 then your program should output The average is 3.0 There are two elements above the average Find the smallest element of the array as well as its index...
1. Write a Python program that performs the following: 2. Defines an array of integers from...
1. Write a Python program that performs the following: 2. Defines an array of integers from 1 to 10. The numbers should be filled automatically without the need for user inputs 3. Find the sum of the numbers that are divisible by 3 (i.e., when a number is divided by 3, the remainder is zero) 4. Swap the positions of the maximum and minimum elements in the array. First, you need to find the maximum element as shown in the...
Write C program that reorders elements of an array of integers such that the new order...
Write C program that reorders elements of an array of integers such that the new order is in descending order (first number being the largest). Must have a main function and a swap function. - int main() will declare an array with the values { 32, 110, 79, 18, 22, 2}. This array will be passed to the swap function. - the void swap function will perform the necessary operations to reorder the elements of the array. - After swap()...
Write a C++ program to find the number of pairs of integers in a given array...
Write a C++ program to find the number of pairs of integers in a given array of integers whose sum is equal to a specified number.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT