Tutorial

 1- Code for Program to display current date and time in C Programming

  #include
  #include
  #include
int main ()
{
 time_t d;
 time(&d);
 //clrscr();
 printf(" current date of Sytem -->> %s " ,ctime(&d));
 getch();
 return 0;   
  }
```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
2-  Reverse of the String 


#include
#include
void reverse12(char *);
int main()
{
    char str[15];
    printf("ENter String\n");
    gets(str);
    printf("\n Reverse String with Library function\n");
    strrev(str);
    printf("Reverse \t %s",str); 
    reverse12(str);
    printf("\n Reverse String with out %s\n",str);
    getch();
    return 0;
    }
/*************** reverse function***********/
void reverse12(char *str)
{
int l=0,i,j;
char *end,*start,temp;
end=str;
start=str;
 while(*(str+l)!='\0')
  l=l+1;
  for(i=0;i<(l-1);i++)
    end++;
    printf("length of string %d",l);
  for ( j=0; j<(l/2); j++)
 {
  temp=*end;
  *end=*start;
  *start=temp;
  start++;
  end--;
  }
}

``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
3-  Sum Of digits 


#include
#include
int main()
{
    int num,sum=0,rem;
    printf("\n Enter the number");
    scanf("%d",&num);
    while(num !=0)
     {
      rem=num%10;
     sum=sum+rem;
     num=num/10;
      }
    
    printf("Sum of the Give number -->> %d",sum);
    getch();
    return 0;
}

``````````````````` ``````````````````````````````````````````````````````````````````````````````````````````````````````````
4-  Decimal to Binary

#include
int main()
{
int n, c, k;
  printf("Enter an integer in decimal number system\n");
  scanf("%d", &n);
  printf("%d in binary number system is:\n", n);
  for (c = 31; c >= 0; c--)
  {
    k = n >> c;
    if (k & 1)
      printf("1");
    else
      printf("0");
  }
  printf("\n");
 getch();
  return 0;
}
``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````

No comments: