Jump to content
xisto Community
htdefiant

What Is The Purpose Of The Percentage Symbol In C?

Recommended Posts

It is called the mod operator and gives remainder.That is num1%num2 will divide num1 from num2 and will display the remainder.In your example it will return 0, as 120 is completely divisible by 2.

Share this post


Link to post
Share on other sites

So, if num2 was 24, it would give me 5 with a remainder of 0?

It wouldn't, or i should say, shouldn't give you the 5. It's purpose is to return the remainder—nothing else. You see this in PHP, too, since PHP is based on C, as well as other programming languages.

Share this post


Link to post
Share on other sites

I think you are not getting it. Try this program in C

main(){ int num1,num2; printf("Enter num1 : "); scanf("%d",&num1); printf("Enter num2 : "); scanf("%d",&num2); printf("num1%num2   is  %d", num1%num2);}

Share this post


Link to post
Share on other sites

You can also try those numbers on google, but I'm not sure it will return the same results as it would in a program.Just enter what you want to calculate onto the search bar and press search.Google has its built in calculator.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.