Thread: Need help with for loops and arrays

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    9

    Need help with for loops and arrays

    Hello, I'm currently a student with a beginner programming skill level and have trouble with programming problem.

    The problem is:

    Let X and Y be two arrays of size 10. Let Z be an array of size 19. The values of arrays X and Y are available in the
    file "input-xy.txt", where every line contains three values: (1) index of the array, i -- an integer; (2) value of element
    in array x, x[i] -- a double value, and (3) value of element i in array y, y[i] -- a double value. The value of x and y ele-
    ments for undefined indices are assumed to be zero.

    Element j of array z, z[j] is computed as below: j = 0, 1, 2, . . . , 18.

    for the summation:
    http://i36.tinypic.com/1roldu.jpg

    Now what I currently have is

    Code:
    #include <stdio.h>
    
    FILE *inp;
    
    main()
    {
    	int i, k, j, x[10], y[10], z[19];
    	int sum = 0
    	
    	inp = fopen("input-xy.txt", "r");
    
    	fscanf(inp, "%d ", &b);
    	fscanf(inp, " %d %d ", &x[b], &y[b]);
    	printf(" %d %d %d ", b, &x[b], &y[b]);
    	
    	for ( j = 0; j <= 9; j++)
    	{
    			k = 0;
    			z[j] = x[k] * y[j-k];
    	
    	for ( j = 11; j <=19; i++)
    	{
    What I want to know does everything look alright? I'm making my k max equal 0 for 0<j<9 so everything would be simplified. That would be all my values for x are less than or equal to 9.

    But also can I do this:
    z[j] = x[k] * y[j-k] in the for loop? Can I write a function with the array bracket?
    Last edited by Skeeter; 10-23-2009 at 12:37 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  2. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  4. Help with arrays and pointers please...
    By crazyeyesz28 in forum C++ Programming
    Replies: 8
    Last Post: 03-17-2005, 01:48 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM