Thread: Help pls for my c code homework

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    3

    Help pls for my c code homework

    Hi . I have a homework which i can't do . Please help me.
    The homework has two questions.

    1. Encode this view with c code(i must use loop and do it with '*' or space)
    the view is that(with the question)
    Help pls for my c code homework-fx917-jpg

    2. Take a string which has 10 element and make string do those
    a) 0. element has all elements plus
    b)1. element has 1. and after '1.' elements plus
    c.
    ...
    d) 8. element has 8. and after '8.' elements plues
    e)9. element must be written without operation
    f) write the last view of string to screen
    (the strings elements must be in (0-100)
    (i can use 4 loop[it's the maximum])
    I may tell it different . Because of it , i'm including the turkish version of questionHelp pls for my c code homework-fx920-jpg

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Hello. We have a homework policy here, so don't expect a complete answer from anybody. We are here to assist people with problems on the journey of learning, not as volunteer free code writers.

    That being said, post your best attempt at solving these assignments, and be sure to put your code in code tags.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    3
    The homework has 4 questions actually.I encoded two of them but i can't solve these problems. I do but it doesn't work . if you want me to share my code i can share the codes which don't work

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    3
    those are my codes which don't work .
    Code:
    #include <iostream>#include <cmath>
    #include <iomanip>
    
    
    using namespace std;
    
    
    
    
    int main()
    {
        int sayiDizisi[10];
        int gecicidegisken=0;
       
        for(int i=1;i<=10;i++)
        {
                do
         {
          printf("Sayiyi giriniz:");
          scanf("%d",&gecicidegisken) ;
          }while(!(0<gecicidegisken && gecicidegisken<100)) ;
          sayiDizisi[i]=gecicidegisken ;
        }
        
        for(int k=1;k<=10 ; k++)
        {
                for(int m=1;m<=10;m++)
                {
                        sayiDizisi[m]+=sayiDizisi[m+1];
                }
                printf("%d",sayiDizisi[k]);
                printf(" ");
    
    
                }
                printf("\n");
                 system("pause");
      
      return 0;
    }

    Code:
    #include <iostream>#include <cmath>
    #include <iomanip>
    
    
    using namespace std;
    
    
    
    
    int main()
    {
        int i, j,k,r ;
        
        for(i=10; i>1; i--)
        {
              
            for(j =1; j<10; j++)
            {
                
                       if(i+j<12)
                       cout<<"*";
                       else
                       cout<<" ";
                    
               
            }
            
            
            
             printf("\n");
        }
       
        
        cout<<endl<<endl;  
        system("pause");
      
      return 0;
    }

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    For starters, this is C++ code, not C, so you should have posted in the C++ forum. (Actually, it's some sort of mish-mosh of C and C++.)

    Looking at your code (I'm checking the first problem you stated, which is the second program you posted), it appears that you tried to code this off the top of your head. That is not going to get you good results.

    Programming requires many different skills, beyond just writing code. For example, there's also problem solving and debugging, to name a few.

    These problems require you to apply problem solving skills, before you even start typing code.

    You should sit down with a pencil and paper, and try to figure out the logic by hand. Take it step by step, making notes on how you would make it happen. Figure out how to do it in words first. The computer is powerful, but not smart, and needs to be told exactly what to do to produce the require output.

    Summarize the problem, perhaps like this:

    Code:
    First problem
    
     - There are nine [rows] lines
     - Each [row] line will has the following output:
        - 9 characters (either '*'s or spaces)
        - a separating space
        - 9 characters (either '*'s or spaces)
    You're obviously going to need loop to print this out, as per the assignment. You know how many rows, and how many space/asterisks in each row, to print.

    Now take your problem solving skills and run with them to figure out the puzzle!

    ---

    I didn't check your second program (the first one posted), but after skimming it, one thing jumped out at me:

    Code:
    int sayiDizisi[10];
    
    // ...
        
    for(int i=1;i<=10;i++)
    {
        // ...
         {
            sayiDizisi[i]=gecicidegisken ;
    "int sayiDizisi[10]" declares an integer array of ten elements. In C/C++, element indices start at zero. Therefore, the only valid indices of this array would be from "sayiDizisi[0]" to "sayiDizisi[9]". Trying to access "sayiDizisi[10]" is wrong, as this is out of bounds of the array.

    The standard way of using a "for()" loop in this manner, with your code, would be as such:

    Code:
    for(int i=0;i<10;i++)
    
    // start at index zero
    // go to index 9 (stop when it gets to 10, which is too high)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for Homework!
    By alionas in forum C Programming
    Replies: 4
    Last Post: 11-20-2010, 10:36 AM
  2. Need help with this code for homework!
    By ch147 in forum C Programming
    Replies: 7
    Last Post: 11-13-2007, 08:16 AM
  3. need help with homework code
    By acidbeat311 in forum C Programming
    Replies: 2
    Last Post: 02-15-2005, 10:43 PM
  4. homework code/looking for suggestions
    By m.albert in forum C++ Programming
    Replies: 3
    Last Post: 03-03-2003, 03:50 PM