C program without main

C program without main function :

usually it is not possible and not even make sense to write a code without main function because program start executing from main. but for the sake of argument this can be done through MACROS. 
i have not experienced it personally but people say that it is very much asked in Interviews.

In following program printf statement is also working without semicolons ' ; '

#include<stdio.h>
#define any main

void any()
{
   if(! printf("this program is without main function\n") )
   {

   }
}

C Program for this Pattern

54321
4321 
321  
21   

1    
CODE :

#include <stdio.h>

int main()
{
    int i, j;
    for(i=5;i>=1;i--)
    {
        for(j=i;j>=1;j--)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}

C Program for this Pattern

12345
2345 
345  
45   

5    
CODE

#include <stdio.h>

int main()
{
    int i, j;
    for(i=1;i<=5;i++)
    {
        for(j=i;j<=5;j++)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}

C Program for this Patters

12345
1234 
123  
12   
1    
CODE :

#include <stdio.h>

int main()
{
    int i, j;
    for(i=5;i>=1;i--)
    {
        for(j=1;j<=i;j++)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}

C Program for this Number Pattern

    5
   54
  543
 5432
54321

CODE:

int main()
{
  int i,j;
  for(i=5;i>=1;i--)
  {
    for(j=1;j<i;j++)
      printf(" ");
    for(j=5;j>=i;j--)
      printf("%d",j);
    printf("\n");
  }
  return 0;
}

strcpy - String Copy


Code :

#include <stdio.h>
#include <stdlib.h>
void xstrcpy(char str[100],char str1[100]);
void main()
{
    char arr[100],arr1[100];
    printf("Enter string ");
    gets(arr);
    xstrcpy(arr,arr1);
}
void xstrcpy(char str[100],char str1[100])
{
    int i;
    for(i=0;arr[i]!='\0';i++)
    {
     str1[i]=str[i];
    }
    printf("copied string is: ");
    puts(str1);
}

String to Lower Case

CODE :


#include<stdio.h>

void main()
{
    int i=0,j=0, length;
    char str[100];

    printf("Enter string : ");
    gets(str);

    for(i=0; str[i]!='\0';i++)
    {}
    length = i ;

    for(j=0; j<length; j++)
    {
        if(str[j]==32)//ascii of space
        {
            continue;//skip iteration to skip space character
        }
        else if(str[j]>=65 || str[j]<=90 )
        {
            str[j]=str[j]+32;
        }
    }
    printf("String in lower case is : ");
    puts(str);

}

Older Posts
© Copyright Encyclopedia of C | Designed By Code Nirvana
Back To Top