Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8053135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:45:20+00:00 2026-06-05T07:45:20+00:00

This is my code: #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <pthread.h> int num_mezzo_1(int

  • 0

This is my code:

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>

int num_mezzo_1(int num_orig);
int num_mezzo_2(int num_orig);

int main(int argc, char *argv[]){
    int num,contatore,tmp=0,tmp_1,tmp_2;
    num=atoi(argv[1]);
    if(num <= 3){
        printf("%d è primo\n", num);
        exit(0);
    }
    else{
        num_mezzo_1(num);
        num_mezzo_2(num);
        tmp=tmp_1+tmp_2;
            //using printf to debug
        printf("t1 %d, t2 %d\n", tmp_1,tmp_2);
        if(tmp>2){
            printf("%d NON è primo\n", num);
        }
        else{
            printf("%d è primo\n", num);
        }
    }
    exit(0);
}

int num_mezzo_1(int num_orig){
    int tmp_1=0,cont_1;
    for(cont_1=1; cont_1<=(num_orig/2); cont_1++){
        if((num_orig % cont_1) == 0){
            tmp_1++;
        }
    }
    //using printf to debug
    printf("\n%d\n", tmp_1);
    return tmp_1;
}

int num_mezzo_2(int num_orig){
    int tmp_2=0,cont_2;
    for(cont_2=((num_orig/2)+1); cont_2<=num_orig; cont_2++){
        if((num_orig % cont_2) == 0){
            tmp_2++;
        }
    }
    //using printf to debug
    printf("\n%d\n\n", tmp_2);
    return tmp_2;
}

This program calculates wheter a number is prime or not.
If i give number 13 as input, the function num_1 has value 1 into tmp_1 and function num_2 has value 1 into tmp_2 and both are correct.
The problem is that tmp=tmp_1+tmp_2 return a big big big value and i don’t understand why.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:45:21+00:00Added an answer on June 5, 2026 at 7:45 am

    You are calling the functions num_mezzo_1() and num_mezzo_2() but you are not storing their return values, so your variables tmp_1 and tmp_2 remain uninitialised.

    Edit: Try changing the code

        num_mezzo_1(num);
        num_mezzo_2(num);
    

    to

        tmp_1 = num_mezzo_1(num);
        tmp_2 = num_mezzo_2(num);
    

    in the else block and see if you get what you expect.

    Working code:

    tmp=(num_mezzo_1(num)+num_mezzo_2(num));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code: #include<stdio.h> #include<stdlib.h> #include<sys/stat.h> #include<sys/types.h> #include<fcntl.h> #include<unistd.h> #include<errno.h> int main(int argc,char
Just to test, I ran this code #include<unistd.h> #include<stdio.h> #include<stdlib.h> int main() { int
Please see this piece of code: #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int i
This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =
Please have a look on this code: #include <unistd.h> #include <stdlib.h> #include <stdio.h> int
I wrote this tiny code: #include <stdio.h> int main() { size_t temp; temp =
I got this C code. #include <stdio.h> int main(void) { int n, d, i;
This is the code #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h>
I written this code: #include <stdio.h> #include <pthread.h> void* cuoco(void* arg) { fprintf(stderr,Inizio codice
I was under the impression that this code #include <windows.h> #include <stdio.h> int WINAPI

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.