I want the remainder of all the numbers inside the loop except the number which i assigned for variable a
for example , if i entered number 5 for a,
the loop is 5 4 3 2 1.
i want my program to take remainder of all these values except 5.
How can i do this ??
Here is my program but it is calculating the remainder of all the numbers including the number i assigned for variable a.
i want it to calculate the remainder of all the numbers except the first value of the loop.

int main(void)
{
		long a,b,c;
		printf ("Enter number:");
		scanf ("%ld",&a);
		c=a;
		for (a=a;a>1;a--)
	{
		b=c%a;
                printf ("%ld\n",b);
	}
		getche ();
}

So what's wrong? The program description doesn't make sense, but the code has only 1 minor error -- the for statement is a little off.

my program is calculating the remainder of the first value as well, i don't want it to do that..i want it to calculate remainder of all the number inside the loop except the first number.
for example:
if the loop values are 10 9 8 7 6 5 4 3 2 1 , program should calculate the remainder of all the numbers except 10.

So don't start your loop with your first value :icon_rolleyes:

no...i've to start it from the first value but i want my program to ignore first value and start calculating the remainder from the second value,
actually the remainder of first value will always be 0, and i don't want to 0 to be printed in the output because i want to make a program which check that the wether the input number is prime or not.

Are you trying to do something like this?

Enter The Number - 7

7 % 2 = 1
7 % 3 = 1
7 % 4 = 3
7 % 5 = 2
7 % 6 = 1

Your for loop is a bit faulty. If you can correct that, the program will run fine. Here is a cryptic hint; you have to remove something from the for loop. Then it'll run.

PS - This method of checking prime numbers is a bit time consuming.

Exactly...! i am trying to do what you've said, can you please tell me what is the problem with my loop

One way could be to put a if condition before the mod operation. If c is equal to a, dont do the mod operation. Else go ahead and do the mod operation

commented: thanks...xufyan +1

Thanks alot abhimanipal
using if here is my program but when i am entering 15 in the output the program is saying that it is a prime number. why ?

int main(void)
{
		long a,b,c;
		printf ("Enter number:");
		scanf ("%ld",&a);
		c=a;
		for (a=a;a>1;a--)
		if (a<c)
	{
		b=c%a;
	}
		if (b==0)
		printf ("not prime");
		else
		printf ("prime");
		getche ();
}

Hey ! Finally my program is Ready and working fine..Yepppieee..!! thanks alot for all the help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.