Saturday, 27 January 2018

c program to print fibonacci series

//program to print fibonacci series
//By:-sujeet kumar

//0 1 1 2 3 5 8 ......
#include<stdio.h>
#include<conio.h>
void main()
{
    int n,a,b,c,i;
    printf("Enter term of series\n");
    scanf("%d",&n);
    a=0;
    b=1;
    printf("\nFibonacci series\n");
    printf("%d\n%d",a,b);
    for(i=1;i<=n;i++)
    {
        c=a+b;
        a=b;
        b=c;
        printf("\n%d\n",c);
    }
    getch();
}

c program to check weather number is neon or not

//program to check neon number
//By:-sujeet kumar
/*Neon number:-Sum of digit of square of any number should be equal to that number.

                e.g:- 1,9 etc
                9=9*9=81
                81=8+1=9*/

#include<stdio.h>
#include<conio.h>
void main()
{
    int n,sq,sum=0;
    printf("enter any number:");
    scanf("%d",&n);
    sq=n*n;
    while(sq>0)
    {
       sum=sum+sq%10;
       sq=sq/10;
    }
    if(sum==n)
        printf("\nNeon number");
    else
        printf("\nNot neon number");
    getch();
}

date calculator in c

#include<stdio.h>
#include<conio.h>


 void main()
 {
     long int dd,mm,yy,inputday,flag=0,i,days,day,year,month;
   
     start:
     printf("\nEnter date [dd/mm/yyyy]\t");
     scanf("%d/%d/%d",&dd,&mm,&yy);
     if(dd>31||mm>12||yy<1918)
     {
         printf("Invalid date!!Please Try again\n");
         goto start;
     }


     printf("\nEnter day\t");
     scanf("%d",&inputday);
      if(yy%400==0 || (yy%100!=0&& yy%4==0))//to check leap year
         {
            flag=1;
          }

           if(mm==2 && dd>28 && flag==0 || mm==2 && dd>29 && flag==1)
          {
              printf("\ninvalid date!!please try again\n");
              goto start;
          }
          if(mm==4||mm==6||mm==9||mm==11)
          {
              if(dd>30)
              {
                   printf("\ninvalid date!!please try again\n");
                   goto start;
              }
          }

          if(mm==1||mm==3||mm==5||mm==7||mm==8||mm==10||mm==12)
          {
              if(dd>31)
              {
                   printf("\ninvalid date!!please try again\n");
                   goto start;
              }
          }


   for(i=1;i<=inputday;i++)
   {
       dd=dd+1;
       if(mm==6&&dd>30||mm==4&&dd>30||mm==9&&dd>30||mm==11&&dd>30)
       {
           dd=1;
           mm++;
           if(mm>12)
           {
               mm=1;
               yy++;

           }
       }
       else if(mm==1&&dd>31||mm==3&&dd>31||mm==5&&dd>31||mm==7&&dd>31||mm==8&&dd>31||mm==10&&dd>31||mm==12&&dd>31)
       {
           dd=1;
           mm++;
           if(mm>12)
           {
               mm=1;
               yy++;
           }
       }
       else if(mm==2)
       {
            if(yy%400==0 || (yy%100!=0&& yy%4==0))//to check leap year
        {
            if(dd>29)
                {
                 dd=1;
                 mm++;
                   if(mm>12)
                     {
                        mm=1;
                        yy++;
                     }}}

          else{
                if(dd>28)
                {
                 dd=1;
                 mm++;
                   if(mm>12)
                     {
                        mm=1;
                        yy++;
                     }}}}
  }



       printf("\nAfter Changing the date:-%02d/%02d/%02d\n\n",dd,mm,yy);
 

 }

C program to retrieve current system date and time

#include<time.h>
#include<stdio.h>
#include<conio.h>
 void main()
 {

     time_t t;
     time(&t);
      printf("Today's date and time :%s",ctime(&t));
      getch();
 }

c program to print fibonacci series

//program to print fibonacci series //By:-sujeet kumar //0 1 1 2 3 5 8 ...... #include<stdio.h> #include<conio.h> void ma...