Saturday, June 30, 2018

Calendar of 21st century















A Program for Displaying the calendar of any year of 21st century





Here's The Program :









#include <stdio.h>
#include <stdlib.h>

int main()
{
int m_year, c_d, d, feb_days, j, j1, m=1, n,da,count,m_c=0;

printf("Enter The Year(2000-2999) : ");
scanf("%d",&m_year);             
//getting year
                                 //1st jan 2000 = saturday


if(m_year>=2000&&m_year<3000)
{
   c_d = count_days(m_year);         //calling count_days() for the     total days between 2000 and the given year

   d = g_year(m_year);              // Calling g_year for No. Of Days in February of the year
   feb_days = 29 - d;

   j = c_d % 7;                     // Getting The Day of 1st Jan

if(j==0)
{
   j1==6;
}
else
   j1=j-1;                             //......//


for(m=1;m<=12;m++)                //A loo to change month
{
   if(m=1)                        //January month table
  {
    n=31;
    printf("\n\nJanuary\n");
    printf("SUN MON TUE WED THI FRI SAT \n\n");


    m_c=month_chart(n,j1);
    j1=m_c;
                                  

  }
   if(m=2)                          //February month table
   {
      n=feb_days;
      printf("\n\nFebruary\n");
      printf("SUN MON TUE WED THI FRI SAT \n\n");
      m_c=month_chart(n,j1);
      j1=m_c;
   }
   if(m=3) //March month table
   {
      n=31;
      printf("\n\nMarch\n");
      printf("SUN MON TUE WED THI FRI SAT \n\n");
      m_c=month_chart(n,j1);
      j1=m_c;
   }
   if(m=4) //April month table
   {
      n=30;
      printf("\n\nApril\n");
      printf("SUN MON TUE WED THI FRI SAT \n\n");
      m_c=month_chart(n,j1);
      j1=m_c;
   }
   if(m=5) //May month table
   {
      n=31;
      printf("\n\nMay\n");
      printf("SUN MON TUE WED THI FRI SAT \n\n");
      m_c=month_chart(n,j1);
      j1=m_c;
   }
   if(m=6) //June month table
   {
      n=30;
      printf("\n\nJune\n");
      printf("SUN MON TUE WED THI FRI SAT \n\n");
      m_c=month_chart(n,j1);
      j1=m_c;
   }
   if(m=7) //July month table
   {
      n=31;
      printf("\n\nJuly\n");
      printf("SUN MON TUE WED THI FRI SAT \n\n");
      m_c=month_chart(n,j1);
      j1=m_c;
   }
   if(m=8) //August month table
   {
      n=31;
      printf("\n\nAugust\n");
      printf("SUN MON TUE WED THI FRI SAT \n\n");
      m_c=month_chart(n,j1);
      j1=m_c;
   }
   if(m=9) //September month table
   {
      n=30;
      printf("\n\nSeptember\n");
      printf("SUN MON TUE WED THI FRI SAT \n\n");
      m_c=month_chart(n,j1);
      j1=m_c;
   }
   if(m=10) //October month table
   {
      n=31;
      printf("\n\nOctober\n");
      printf("SUN MON TUE WED THI FRI SAT \n\n");
      m_c=month_chart(n,j1);
      j1=m_c;
   }
   if(m=11) //November month table
   {
      n=30;
      printf("\n\nNovember\n");
      printf("SUN MON TUE WED THI FRI SAT \n\n");
      m_c=month_chart(n,j1);
      j1=m_c;
   }
   if(m=12) //December month table
   {
      n=31;
      printf("\n\nDecember\n");
      printf("SUN MON TUE WED THI FRI SAT\n\n");
      m_c=month_chart(n,j1);
      j1=m_c;
   }
}

}
else
 printf("Error");

return 0;
}


int count_days(int year)                       
// Getting the total days between 2000 and the given year
{
   int ly,non_ly,tot_days,leap_y;
   leap_y = g_year(year);                       // Calling g_year
   ly = (year - 2000)/4;
   non_ly = year - 2000 - ly;
   tot_days = (ly*366) + (non_ly*365) + leap_y;         //This is for 2000 is leapyear


   return tot_days;
}



int g_year( int l_y)                     
//Cheaking wheather the given year is leapyear or not
{
   int c;


   if(l_y%4==0) 
      c = 0;

   if(l_y%4!=0)
      c=1;

   return c;
}


int month_chart(int last_date , int j_val)
{
   int mat[6][7];
   int i,j,a=1,n;
   for(i=0;i<6;i++)
   {
      for(j=0;j<7;j++)
      {
         mat[i][j]=0;

      }

   }
   for(i=0;i<6;i++)
  {
      if(i==0)
      {
         for(j=j_val;j<7;j++)
         {
             mat[i][j]=a;
             a++;
         }
      }
      else
     {
         for(j=0;j<7;j++)
         {
            mat[i][j]=a;
            a++;
            if(a>last_date)
              break;
          }
          if(a>last_date)
         {
            if(j==6)         
//Getting The 1st Day of next month
            {
                n=0;
            }
            if(j!=0)
            {
                n=j+1;
            }
          
            break;
         }

      }
   }
   for(i=0;i<6;i++)
   {
      for(j=0;j<7;j++)
      {
          if(mat[i][j]!=0)
          {
              printf("%3d ",mat[i][j]);
          }

          else
             printf(" ");
      }
      printf("\n");
   }

return n;
}














Video On The Program : https://youtu.be/HAPVJ50GZzshttps://youtu.be/HAPVJ50GZzs

Thursday, May 10, 2018

Name Initials Array In C



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

main()
{
char st[200],a[200];
int i,j=0,k;

gets(st);
k=strlen(st);

a[0]=st[0];
j++;
for(i=0;i<k;i++)
{
if(st[i]==' ')
{
a[j]='.';
j++;
a[j]=st[i+1];
j++;
}
}
puts(a);
getch();
}



OUTPUT :

Pankaj Deb Roy


P.D.R

Toggle in C



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

main()
{
char st[200],a;
int i,j,k;
printf("Toggle\n");
gets(st);
k=strlen(st);
for(i=0;i<k;i++)
{
a=st[i];
if(a>=97 && a<=122) //small to cap
{
st[i]=st[i]-32;

}
if(a<=90 && a>=65) //cap to small
{
st[i]=st[i]+32;

}
}
puts(st);
getch();

}



OUTPUT :

Toggle

HALLO WORLD !
hallo world !


Searching In Array



//Searching In Array
#include<stdio.h>
#include<conio.h>

int main()
{
int i,n,flag=0,a[10],num;
char y,get;
while(get='y')
{
printf("Enter The Aray Length : ");
scanf("%d",&n); //Deside length of the aray
printf("Enter The Numbers : ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}

printf("Enter The Number You Want To Search : ");
scanf("%d",&num);
for(i=0;i<n;i++)
{
if(a[i]==num)
{
flag=1; //found the number 
break;
}
}

if(flag==1)
printf("Found");
else
printf("Not Found");
flag=0;
fflush(stdin);
printf("\n\nRetry :(y/n) ");
scanf("%c",&get);
if(get!='y')
break;
}
getch();
return 0;
}


OUTPUT :
Enter The Aray Length : 5
Enter The Numbers : 45
75
54885
5454
15
Enter The Number You Want To Search : 55
Not Found

Retry :(y/n) n

Monday, May 7, 2018

Write a C program to find the Sum of natural numbers in a given range.



#include<stdio.h>

int main()
{
int n1,n2, i,sum=0;

printf("Enter The Range Number  : ");
scanf("%d%d",&n1,&n2);

for(i=n1;i<=n2;i++)
{
sum=sum+i;
}
printf("Sum = %d",sum);
return 0;
}




OUTPUT

Enter The Range Number  : 2    9

Sum = 44

WACP to print the value of a series S=1+X+X3+X5 +…. +nth term.




#include<stdio.h>
#include<math.h>
#include<conio.h>
int main()
{
int n,i,j=1,sum=1;
printf("Enter The Last Number : ");
scanf("%d",&n);

for(i=0;i<n;i++)
{
sum=sum+pow(n,j);
j=j+2;
}
printf("Sum = %d",sum);

        getch();

        return 0;
}




OUTPUT : 

Enter The Last Number : 3
Sum = 274


NB: (1+3^1+3^3+3^5)=274

Write a C program to find the Palindrome numbers in a given range.



Palindrome numbers:   A palindromic number or numeral palindrome is anumber that remains the same when its digits are reversed. Like 16461, for example, it is "symmetrical". The term palindromic is derived from palindrome, which refers to a word (such as rotor or race car) whose spelling is unchanged when its letters are reversed.



#include<stdio.h>
int main()
{
int n1,n2, n3,n,s,r;
printf("Enter The Range : ");
scanf("%d%d",&n1,&n2);
printf("Palindrome numbers are : ");
for(n=n1;n<=n2;n++)
{
n3 = n;
for(s=0;n3>0;n3=n3/10)
{
r=n3%10;
s=s*10+r; //Reverse number
}
if(s==n)  
           printf("%d ",s);             //Palindrome 

}
        return 0;
}



OUTPUT:

Enter The Range : 2      200

Palindrome numbers are : 2 3 4 5 6 7 8 9 11 22 33 44 55 66 77 88
99 101 111 121 131 141 151 161 171 181 191