Thread: solve this problem using array..

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    4

    solve this problem using array..

    can someone help me solve this problems pls i cant really understand this.. it uses array on this problems..im newby here just wanna know the answers of this questions

    Code:
    1. Write a C program that will search for the largest value in an array of integers of length 10.
    2. Write a C program that will search for the smallest value in an array of integers of length 10.
    3. Write a C program that will print the odd positioned elements in an array of 10 integers.
    4. Write a C program that will print the even positioned elements in an array of 10 integers.
    5. Write a C program that will arrange the elements of a 10-integers array in ascending order.
    6. Write a C program that will arrange the elements of a 10-integers array in descending order.
    7. Write a C program that will compute and display the average of a 20-element array whose values are inputted by the user.
    8. Write a program that will output all the even numbers found in an array of 20 integers. display also the sum of the values found.
    9. Write a program that will output all the odd numbers found in an array of 20 integers. display also the sum of the values found.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If you don't want to work on your homework, then it won't get done, here. You have to show some work.

    You won't get far in programming in C, without a work ethic for the subject.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    A piece of code

    Code:
    #include <stdio.h>
    
    int find_largest(int* arr, const int length) {
      int index   = 0;
      int largest = 0;
      for (index = 0; index < 10; ++index)
        if (*(arr + index) > largest)
          largest = *(arr + index);
    }
    
    int main() {
      int arr[]  = {1, 67, 34 , 24, 53, 53, 24, 90, 83, 109};
      printf("largest number = %d\n", find_largest(arr, 10));
    
      return 0;
    }
    Please try to write the sample code yourself first and if you face any problem after research then turn up to here otherwise you will not learn that fast. It z just my advice

  4. #4
    Registered User
    Join Date
    Oct 2009
    Posts
    4
    i have code here for no. 1 i dont know if this is correct..

    Code:
    #include <stdio.h>
    
    void main()
    {
    int max,min,i,j,k,n,a[100];
    
    	printf("How Many Numbers You Want To Enter==");
    	scanf("%d",&n);
    	printf("Enter %d Numbers\n",n);
    	for(i=0;i<n;i++)
    	{
    		scanf("%d",&a[i]);
    	}
    	max=min=a[0];
    	j=k=0;
    	for(i=1;i<n;i++);
    	{
    	if(a[i]>max)
    	{
    	max=a[i];
    	j=i;
    	}
    	if(a[i])
    	{
    	min=a[i];
    	k=i;
    	}
    	}
    	printf("\nMaximum Number is %d",max);
    
    }

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by juncas17 View Post
    i have code here for no. 1 i dont know if this is correct..
    Why not? Did you compile it? Did it give you the right answer? All the time? How can you not know if it's correct?


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie Question: sizeof() problem in function
    By Xeyide in forum C Programming
    Replies: 3
    Last Post: 09-04-2009, 12:05 AM
  2. 2d array problem
    By LiLgirL in forum Windows Programming
    Replies: 1
    Last Post: 03-15-2004, 02:23 PM
  3. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  4. problem: reading user input into an array
    By alpha561 in forum C Programming
    Replies: 13
    Last Post: 05-24-2002, 07:23 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM

Tags for this Thread