Pages

Monday, March 31, 2014

C Program to display its own source code using __FILE__

#include <stdio.h>
int main()
{
    FILE *fp;
    char c;
    fp = fopen(__FILE__,"r");
    do {
         c = getc(fp);
         putchar(c);
    }
    while(c != EOF);
    fclose(fp);
    return 0;
}

C Program to display its own source code using __FILE__

#include <stdio.h>
int main()
{
    FILE *fp;
    char c;
    fp = fopen(__FILE__,"r");
    do {
         c = getc(fp);
         putchar(c);
    }
    while(c != EOF);
    fclose(fp);
    return 0;
}

C Program to check a number has perfect square or not

/** C Program to check Perfect Square **/
#include <stdio.h>
int main()
{
    int a, n;
    printf("Enter a number: ");
    scanf("%d", &n);
    for(a = 0; a <= n; a++)
    {
        if (n == a * a)
        {
            printf("YES");
            return 0;
        }
    }
    printf("NO");
    system("pause");
    return 0;
}