Freelancer

IQ comment

IQ comment - C Programming Example

This is an example of a simple iq test done simply for amusement through C Programming, beginner level.
C programming example
Human Brain

C Programming Code


#include<stdio.h>
#include<conio.h>
main()
{
    int a;
    printf("Input your IQ or the IQ of a person \n");
    scanf("%d",&a);
    if (a<=0)
        printf("Dear Homo sapien, the earth was not meant for you");
    else if (a==0)
        printf("Maybe during production a brain was missed as input in you");
    else if (a>=1&&a<5)
        printf("Dear one, even a baby with diapers is smarter than you");
    else if (a>=5&&a<=9)
        printf("Hey, congratulation,you are on the right path keep developing your IQ");
    else if (a>9&&a<=10)
        printf("Damn! If you still didn't do anything great you are a disgrace");
    else if (a>10)
        printf("In a test within 1-10 you wrote more than 10, just proves how dumb you are");
    getch();
}

Output of code

C programming example
IQ comment

Explanation of code

·        #include<stdio.h>
#include<conio.h>
Ø  This are called header file.A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source filesThe C programming language provides many standard library functions for file input and output. These functions make up the bulk of the C standard library header <stdio.h>.In the other hand <conio.h> is a C header file used mostly by MS-DOS compilers to provide console input/output. It is not part of the C standard library or ISO C. This header declares several useful library functions for performing "console input and output" from a program.

·         main()
Ø  In C, program execution starts from the main() function. The main function can in-turn call other functions. When main calls a function, it passes the execution control to that function. The function returns control to main when a return statement is executed or when end of function is reached.
·            int a;
Ø  int is a variable or data type. A variable declared to be of type int can be used for storing numbers which don’t  have decimal points. Here we declare “a”variable in int type.
·         printf() function
Ø  C uses printf() function to write from the input devices. This function has been declared in the header file called stdio.h . Any text written within the pair of quotes ("") is displayed as such by printf() function on the screen. 
·         scanf() function
Ø  This function is used to get input from the user of the program. scanf(“%d”,&a”) is used here. So, this program will read in a int value for “a” variable that the user enters on the keyboard (%d is for int values. As there is “&a”, the number user enters will be the value of “a” variable).

    printf("Input your IQ or the IQ of a person \n");
    scanf("%d",&a);
Here , the input or in this case the iq of a human will be given in integer type and the program will scan and save that input in “a”.

    if (a<=0)
        printf("Dear Homo sapien, the earth was not meant for you");
As this code is purely for recreation, when someone puts the input below 0 the statement written in printf will be shown as output as the condition for this loop is a<=0.
else if (a>=1&&a<5)
        printf("Dear one, even a baby with diapers is smarter than you");
As this code is purely for recreation, when someone puts the input between 1 and 5 the statement written in printf will be shown as output as the condition for this loop is a>=1&&a<5.

    else if (a>=5&&a<=9)
        printf("Hey, congratulation,you are on the right path keep developing your IQ");
As this code is purely for recreation, when someone puts the input between 5 and 9 the statement written in printf will be shown as output as the condition for this loop is a>=5&&a<9.

   else if (a>9&&a<=10)
        printf("Damn! If you still didn't do anything great you are a disgrace");
As this code is purely for recreation, when someone puts the input between 9 and 10 the statement written in printf will be shown as output as the condition for this loop is a>=9&&a<10.

else if (a>10)
        printf("In a test within 1-10 you wrote more than 10, just proves how dumb you are");
As this code is purely for recreation, when someone puts the input over 5 10 the statement written in printf will be shown as output as the condition for this loop is a>10.

And finally getch(); is written to end the program.

No comments

Powered by Blogger.