Skip to content

Instantly share code, notes, and snippets.

View cynx's full-sized avatar
👓
blow

cynx cynx

👓
blow
View GitHub Profile
@cynx
cynx / atoi program in C
Created June 9, 2014 16:59
C program to convert string of numbers to their numeric equivalent
#include <stdio.h>
int main()
{
int atoi (char s[]);
printf("%d",atoi("239"));
return 0;
}
@cynx
cynx / Count Program
Last active August 29, 2015 14:02
C Program to count words, new line and characters
//count words, new line and characters
#include <stdio.h>
#define IN 1
#define OUT 0
int main()
{
int c, nc, nl, nw, state;
@cynx
cynx / Digit Count
Created June 9, 2014 17:16
C Program to count occurance of digits and white space and others
//to count occurance of digits and white space and others
#include <stdio.h>
int main()
{
int i,c,nwhites,nothers;
int ndigits[10];
c=nwhites=nothers=0;
@cynx
cynx / Binary Decimal Conversion
Created June 9, 2014 17:55
C program to covert 'Decimal to Binary' and 'Binary to Decimal'
/* C programming source code to convert either binary to decimal or decimal to binary according to data entered by user. */
/* From http://www.programiz.com/ */
#include <stdio.h>
#include <math.h>
int binary_decimal(int n);
int decimal_binary(int n);
int main()
{
int n;
@cynx
cynx / Lower Case
Created June 10, 2014 02:21
C function to convert string to lower case
/* convert C to lower case
int lcase (int c)
{
if (c >= 'A' && C <= 'Z')
retunr c + 'a' - 'A';
else
return c;
}
@cynx
cynx / String concatenate
Created June 10, 2014 02:54
C function to concatenate string
void strct(char s[],char t[]);
int main()
{
char s[7] = "mehul ";
char t[6] = "dhara";
strct(s,t);
printf("%s",s);
return 0;
@cynx
cynx / Extract Binary digits
Created June 11, 2014 02:43
C function to extract n bits from p position of number x
#include <stdio.h>
unsigned getbits(unsigned x,int p,int n);
int main()
{
printf("%d",getbits(5, 4, 3));
return 0;
}
@cynx
cynx / Setbits
Created June 11, 2014 10:27
C program that returns x with the n bits that begin at position p set to the rightmost n bits of y, leaving the other bits unchanged.
#include <stdio.h>
unsigned setbits(unsigned x, int p, int n, unsigned y);
int main()
{
printf("%d", setbits(17, 4, 3, 13));
return 0;
}
unsigned setbits(unsigned x, int p, int n, unsigned y)
{
@cynx
cynx / BitCount
Created June 12, 2014 02:58
Count number of bits
int bitcount(unsigned x)
{
int b;
for(b = 0;x != 0;x &= x-1)
++b;
return b;
}
@cynx
cynx / RightRotate
Created June 17, 2014 13:35
C function to rotate right
unsigned rightrot(unsigned x, unsigned n)
{
while (n > 0) {
if ((x & 1) == 1)
x = (x >> 1) | ~(~0U >> 1);
else
x = (x >> 1);
n--;
}
return x;