Thread: i cant find the error... Plz help!!

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    82

    i cant find the error... Plz help!!

    Only taking 1 input.. then stopped working error .. plz help me............ and plz point out other mistakes too. I will be grateful to you for the help...


    here is the question
    #1: Write a program that calculates the gcd’s (greatest common divisors) of each of the two consecutive elements of an array of size n and prints them as shown in the example Problem below. For this you have to write a function gcdMulti(int[]) that would take the integer array as argument, the array size and print the GCD of the consecutive elements. Furthermore, gcdMulti() must call gcd() which returns the GCD of two integers. Identify the complete signatures of each of these functions and implement them.

    Example:

    Input:

    2 4 6 3 9

    Output:

    GCD1=2; GCD2=2; GCD3=3; GCD4=3
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    
    //--gcdMulti Definition--
    void gcdMulti(int arr[],int size){
         
         int i=0;   
         int stor=0;           
         for(i=0; i<size; i++){
                  stor=gcd((arr+i),(arr+(i+1)));
                  }
                  printf("GCD: %d \n",stor);
         
    }
    //**gcdMulti def End**
    
    //---------------------
    
    //--gcd definition--
    int gcd(int a,int b){
        int temp,stor;
        
        if(b < a){
              temp=a;
              a=b;
              b=temp;
              }
              
        for(temp=0; temp<a; temp++){
                    if(a%temp == 0 && b%temp==0){
                              stor=temp;
                              }
                              }
        return stor;
    }
    //**gcd def END**
    
    //---------------------
    
    //--Int main--
    int main()
    
    {
        int *arr,size,i;
        
        arr=(int *)malloc(size*sizeof(int));
        
        printf("Enter the no of value: ");
         scanf("%d",&size);    
         printf("Enter %d values: ",size);
         for(i; i<size; i++){
               scanf("%d",*(arr+i));           
                          }
         gcdMulti(arr,size);                 
         free(arr);
        
        getch();
        return 0;
    }
    //**int main END**
    Last edited by fredsilvester93; 11-29-2011 at 02:28 PM. Reason: Required

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Code:
    for(i=0; i<size i++){
    You're missing a semi-colon.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    82
    Quote Originally Posted by rags_to_riches View Post
    Code:
    for(i=0; i<size i++){
    You're missing a semi-colon.
    ya i foudn that error... but still there are more errors... program is not taking more than 1 input

    stopped workng error is shown....

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    88
    Code:
     arr=(int *)malloc(size*sizeof(int));
    What is in the variable size at the point this statement is executed ?

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    82
    thnx alot....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't seem to find the error here.
    By DavidP in forum C++ Programming
    Replies: 5
    Last Post: 12-30-2008, 01:26 PM
  2. Cant Find Error
    By Toonzaka in forum C Programming
    Replies: 3
    Last Post: 08-10-2008, 02:00 PM
  3. Cannot find error
    By rwmarsh in forum Game Programming
    Replies: 6
    Last Post: 09-20-2006, 06:48 AM
  4. HELP PLEASE: I can't find the error
    By reivaj7999 in forum C++ Programming
    Replies: 3
    Last Post: 08-15-2005, 07:47 PM
  5. can't find the error
    By noor_mirza in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2002, 12:58 AM