[Solved] New to C how to format function [closed]

ObsidianEris Asks: New to C how to format function [closed]
So I had to program something that would find the nth prime. I had no issue with that, but for the next part, I have to take out the part that checks if it’s prime and turn it into a function. I am new to C so I’m struggling with syntax and semantics.

Original program:

Code:
#include <stdio.h>
#include <math.h>

int main()
{ 
   int rangenumber, c=0, num=2, i, test=0;
   print("Enter Nth Numbern");
   scanf("%d", &rangenumber); 

   while (c!=rangenumber)
   {
      int count = 0;
      for ( i=2; i<= sqrt(num); i++)
   {
         if(num % i==0)
         {
            count++;
            break;
         }
   }
  if(count == 0)
  {
      c++;
      test = num;
  }
  num = num + 1;
  }
  printf("the %dth prime number is %dn" ,rangenumber, test);
  return 0;
}

So what would it look like if I put the part that checks for primes into a function named “check_if_prime”? Any help would be appreciated! I just cant seem to get the format right.

EDIT: I cant really show you all I have tried as I have redone it several times over but basically I have been moving those nested loops into a function here’s what I have currently which I know is wrong.

Current (incorrect) code:

Code:
#include<stdio.h>
#include<math.h>

int check_if_prime (int); //prof wants a prototype, I think its returning an int

int rangenumber, c=0;
int isPrime;

printf("Enter Nth Numbern");
scanf("%d", &rangenumber);

while(c!-rangenumber)
{

isPrime =check_if_prime(rangenumber);
}
printf("The %dth prime number is %dn" , rangenumber, test);
return0;
}


int check_if_prime (int number)
{
   int num-2, test=0, i;
   int count=0;
   for (i=2; i<= sqrt(num); i++)
   {
      if (num % i==0;)
      {
        count++;
        break;
      }
   }
   if(count == 0)
      {
        c++;
        test = num;
      }
num =num+1;
}
return test;
}

So obviously that’s incorrect as I’m still trying to figure out what variables go in the function and which go in the main so that it turns out correctly and there’s about 15+ other variations of me moving loops and variable in and out of that function trying to get it to work. Sorry for formatting issues I’m only in my first C class.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.