Checksum program in c

On-campus and online computer science courses to Learn the basic concepts of Computer Science.This tutorial will cover c ,c++, java, data structure and algorithm,computer graphics,microprocessor,analysis of algorithms,Digital Logic Design and Analysis,computer architecture,computer networks,operating system.
code in C:
#include<stdio.h>
char a[100];
int bin[160],sum[100],index,no,i,count,temp[16],k,carry=0,len;
void binary();
void add(int j);
int main()
 {
 printf("Enter Data length:");
  scanf("%d",&len);	
  printf("Enter Data\n");
  scanf("%s",a);
  binary( );
  for(k=0;k<16.;k++)
  	temp[k]=bin[k];
  
  for(k=16;k<len*4;k=k+16)
   	add(k);

  printf("\n\n Checksum \n");
  for(i=0;i<16;i++)
  {
   temp[i]= temp[i]==0 ?1:0;
   printf("%d",temp[i]);
  } 
 return 0;
 }

void binary( )
{    
    index=3;
	for(i=0;i<len;i++)
	{
		if(a[i]>='0'&&a[i]<='9')
		no=a[i]-'0'; 	
		      
        if(a[i]>='A'&&a[i]<='F')
        	no=a[i]-55;
        
		count=0;
		k=index;   
		while(count<4)
		{
         	bin[k--]= no % 2;
         	no=no/2;
         	count++;
    	}   
    	index=index+4; 		       	
	}
}

void add( int j)
{
  for(i=j+15;i>=j;i--)
  {
  	sum[i-j] =(bin[i] + temp[i-j] + carry) % 2;
  	carry     =(bin[i] + temp[i-j] + carry) / 2;
  }
  if(carry==1) 
  {    	i=j+15;
   		while(carry!=0)
   		{
   			sum[i-j] =(bin[i] + temp[i-j] + carry) % 2;
   			carry 	  =(bin[i] + temp[i-j] + carry) / 2;
    		i--;
   		}
  }
  for(i=0;i<16;i++)
	 temp[i]=sum[i];
}
output:-
Enter Data length:20
Enter Data
45120731297186301946
Checksum
1110101011010100
--------------------------------

0 comments: