Jump to content

C++ | Mathematic


drk

Recommended Posts

Hi guys!

I started learning these days and I need know this:

int a = 1, b = 2, c = 3; 
int result = ++a/a&&!b&&c||b--||-a+4*c>!!b; 

I know that it's needed to put two equal symbols to the system understand that it's to write "!!" and not use "!", but I can't understand this: c>!!b.

Someone, help me please and sorry for can't explain good.

Link to comment

Okay. Thanks, now can someone explain me in this code:

void main() 
{ 
    int i, j, k; 
    printf ( "\n" ); 
    for ( k = 0; k <= 1; k++ ) 
    { 
        printf ( "\n" ); 
        for ( i = 1; i < 5; i++ ) 
            printf ( "Tabuada do %3d      ", i + 4 * k + 1 ); 
            printf ( "\n" ); 
            for ( i = 1; i <= 9; i++ ) 
            { 
                for ( j = 2 + 4 * k; j <= 5 + 4 * k; j++ ) 
                    printf ( "%3d x%3d = %3d     ", j, i, j * i ); 
                    printf ( "\n" ); 
            } 
    } 
} 

Why just in 2 for loops it's needed keys { } ?

Link to comment

It's optional use { } in for loop.

#include <iostream> 
  
int main( ) 
{ 
    for ( int i = 0; i < 5; i++ ) 
        printf( "%d \n", i ); 
    return 0; 
} 

Output:

  
0 
1 
2 
3 
4 
  

Also

#include <iostream> 
  
int main() 
{ 
    int i = 10; 
    if ( i ) 
        printf( "%d \n", i ); 
    return 0; 
} 

Output:

10 

You can test it here: http://codepad.org/

Also you need better read documentation about c++ :mrgreen:

Edited by Guest
Link to comment
It's optional use { } in for loop.

#include <iostream> 
  
int main( ) 
{ 
    for ( int i = 0; i < 5; i++ ) 
        printf( "%d \n", i ); 
    return 0; 
} 

Output:

  
0 
1 
2 
3 
4 
  

Also

#include <iostream> 
  
int main() 
{ 
    int i = 10; 
    if ( i ) 
        printf( "%d \n", i ); 
    return 0; 
} 

Output:

10 

You can test it here: http://codepad.org/

Also you need better read documentation about c++ :mrgreen:

Also you need better read documentation about c++ :mrgreen:

I'm already learning C++ from a book I bought and It has much exercises and these things but don't explain somethings.

Link to comment

I don't know if I must create a new topic for this, so here we go:

#include "stdafx.h" 
#include <Windows.h> 
#include <stdint.h> 
  
int main() 
{ 
    int nPrimo; 
    int bPrimo = 0; 
    printf ( "Type a number: " ); 
    scanf_s ( "%d", &nPrimo ); 
    for ( int i = 2; i <= nPrimo; i++ ) 
    { 
        if ( nPrimo%i != 0 )  
        { 
            bPrimo = 1; 
        } 
                 
        if ( bPrimo == 0 ) 
        { 
            MessageBox ( NULL, L"The number is prime!", L"Information", MB_ICONQUESTION ); 
            return 0; 
        } 
        else 
        { 
            MessageBox ( NULL, L"The number is not prime!", L"Information", MB_ICONQUESTION ); 
            return 1; 
        }    
    } 
} 

I made this ( classes exercise xD ), It works now, but if number is 3 it says number is not prime lol

I don't know why, can someone help? :D

I can't understand this shitty prime numbers :?

Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...