Saturday 15 July 2017

PRINT ASCII TABLE/ASCII CHART

#include
int main()
{
unsigned char count;
for(count=32;count<255 count="" p="">{
printf(" %3d - %c",count,count);
if(count % 6==0)
printf("\n");
}
return 0;

}
IT REALLY  WORKS....

Tuesday 11 July 2017

INTERESTING FACT ON C


Below is one of the interesting facts about C programming:

1) The case labels of a switch statement can occur inside if-else statement

#include

int main()
{
    int a = 2, b = 2;
    switch(a)
    {
    case 1:
        ;

        if (b==5)
        {
        case 2:
            printf("GeeksforGeeks");
        }
    else case 3:
    {

    }
    }
}
Run on IDE
Output :GeeksforGeeks

Monday 10 July 2017

FACTORIAL


#include
int main()
{
    int n, i;
    unsigned long long factorial = 1;

    printf("Enter an integer: ");
    scanf("%d",&n);

    // show error if the user enters a negative integer
    if (n < 0)
        printf("Error! Factorial of a negative number doesn't exist.");

    else
    {
        for(i=1; i<=n; ++i)
        {
            factorial *= i;              // factorial = factorial*i;
        }
        printf("Factorial of %d = %llu", n, factorial);
    }

    return 0;
}

Tuesday 4 July 2017



               
1.In a file contains the line "I am a boy\r\n" then on reading this line into the array str using fgets(). What will str contain?
A.            "I am a boy\r\n\0"
B.            "I am a boy\r\0"
C.            "I am a boy\n\0"
D.            "I am a boy"
TRY  IT YOURSELF


Answer: Option C
Explanation:
Declaration: char *fgets(char *s, int n, FILE *stream);
fgets reads characters from stream into the string s. It stops when it reads either n - 1 characters or a newline character, whichever comes first.

Therefore the  string str  contain “ I am a boy\n\0”.

Monday 3 July 2017

MAGIC SQUARE PUZZLE


/*
 * C Program to Solve the Magic Squares Puzzle without using 
 * Recursion
 */
#include

void magicsq(int, int [][10]);

int main( )
{
    int size;
    int a[10][10];

    printf("Enter the size: ");
    scanf("%d", &size);
    if (size % 2 == 0)
    {
        printf("Magic square works for an odd numbered size\n");
 A   }
    else
    {
        magicsq(size, a);
    }
    return 0;
}

void magicsq(int size, int a[][10])
{
    int sqr = size * size;
    int i = 0, j = size / 2, k;

    for (k = 1; k <= sqr; ++k) 
    {
        a[i][j] = k;
        i--;
        j++;

        if (k % size == 0) 
        { 
            i += 2; 
            --j; 
        }
        else 
        {
            if (j == size) 
            {
                j -= size;
            }
            else if (i < 0)
            {
                i += size;
            }
        }
    }
    for (i = 0; i < size; i++)
    {
        for (j = 0; j < size; j++)
        {
            printf("%d  ", a[i][j]);
        }
        printf("\n");
    }
}
RUN IT..............