Advertisements

Search results for signed

Example:[1]

            Write a c program function to find the maximum of three given integers.
          

            #include <stdio.h>
unsigned int max;
unsigned int maxi(unsigned int num1,unsigned int num2,unsigned int num3);
int main()
{
    unsigned int max_result;
    max_result = maxi(12,24,34);
    printf("The max result is %d\n",max_result);
    return 0;
}
unsigned int maxi(unsigned int num1,unsigned int num2,unsigned int num3)
{
    max = num1;
    if(num2 > max)
    {
        max = num2;
    }
    if(num3 > max)
    {
        max = num3;
    }
    return max;
}
          
Example:[2]

            Write a c program function to calculate the sum of even integers from 2 to 100.
          

            #include <stdio.h>
unsigned int evensum();
unsigned int sum;
int main()
{
    unsigned sum;
    sum = evensum();
    printf("sum is %d\n",sum);
    return 0;
}
unsigned int evensum()
{
    unsigned int i;
    for(i = 2;i <= 100;i += 2)
    {
        sum += i;
    }
    return sum;
}
          
Example:[3]

            Write a c program function to calculate the sum of odd integers from 1 to 100.
          

            #include <stdio.h>
unsigned int oddsum();
unsigned int sum;
int main()
{
    sum = oddsum();
    printf("sum is %d\n",sum);
    return 0;
}
unsigned int oddsum()
{
    unsigned int i;
    for(i = 1;i <= 100;i += 2)
    {
        sum += i;
    }
    return sum;
}
          
Example:[4]

            Write a c program function to check a given number is even parity(even no of 1s) or odd parity(odd no of 1s).
          

            #include <stdio.h>
int CheckParity(int );
int main()
{
	unsigned int num = 12;
	printf("Parity of %d,%s\n",num,(CheckParity(num)? "odd" : "even"));
	return 0;
}

int CheckParity(int n)
{
	int parity = 0;
	while(n)
	{
		parity = !parity;
		n = n & (n-1);
	}
	return parity;
}
          
Example:[5]

            Write a C program to find longest sequence of elements in an array.
          

            #include <stdio.h>
int result = 0,f_result = 0;
unsigned int find_long(int a[]);
int main()
{
    int aa[] = {0,2,3,8,9,10,11,12,18,19,20,21,22,23,24};
    unsigned int lon;
    lon = find_long(aa);
    printf("The Long sequence is %d\n",lon);
    return 0;
}
unsigned int find_long(int a[])
{
    int len = 15;
    unsigned int i;
    for(i = 1;i < len;i++)
    {
        if((a[i] - a[i-1]) == 1)
        {
            result++;
            if(result >= f_result)
            {
                f_result = result;
                printf("f_result is %d\n",f_result);
            }
        }else
            {
                result = 0;
                printf("result is %d\n",result);
            }
    }
    return f_result+1;
}

          
Example:[6]

            Write a program to find the number of times that a given word(i.e. a short string) occurs in a sentence (i.e. a long string!).
          

            #include <stdio.h>
#include <string.h>
unsigned int search_word(char *,char *);
int main()
{
    char *s_str = "the";
    char *l_str = "the word searching for from these sentence is the.";
    unsigned int result;
    result = search_word(s_str,l_str);
    printf("Small string is found %d times in long string\n",result);
    return 0;
}
unsigned int search_word(char *s1,char *s2)
{
    int times = 0;
    int i = 0,j = 0,k = 0;
    int size = strlen(s1);
    printf("Size of small string \" %s \" is: %d\n",s1,size);
    while(s2[j] != '\0')
    {
        if(j >= (size - 1))
        {
            if(s2[j] == s1[size-1] && s2[j-1] == s1[size-2] && s2[j-2] == s1[size-3])
            {
                times = times + 1;
            }
        }
        j++;
    }
    return times;
}
          
Example:[7]

            Write a program to swap the 4bytes of an integer. If input is provided as 0x12345678 output is generated as 0x78563412.
          

            #include <stdio.h>
union out
{
   struct
   {
      unsigned char ll;
      unsigned char lh;
      unsigned char hl;
      unsigned char hh;
   }in;
   unsigned int b;
};
int main()
{
   union out aa;
   aa.b = 0x12345678;
   printf("Before swapping:%x\n", aa.b);
   unsigned char ll = aa.in.ll;
   unsigned char lh = aa.in.lh;
   aa.in.ll = aa.in.hh;
   aa.in.hh = ll;
   aa.in.lh = aa.in.hl;
   aa.in.hl = lh;
   printf("After swapping:%x\n", aa.b);
   return 0;
}
          
Example:[8]

            Write a function to determine whether the machine is Little Endian or Big Endian.
          

            #include <stdio.h>
unsigned int EndianCheck();
union endian
{
   unsigned int a;
   char b;
};
int main()
{
   unsigned int res;
   res = EndianCheck();
   if(res == 0)
   {
      printf("Little endian\n");
   }else
   {
      printf("Big endian\n");
   }
   return 0;
}
unsigned int EndianCheck()
{
   union endian test;
   test.a = 1;
   if(test.b == 1)
   {
      return 0;
   }else
   {
      return 1;
   }
}
          
Example:[9]

            Write a C program function  to swap the nibbles in a byte.
          

            #include <stdio.h>
unsigned char function(unsigned char );
int main()
{
	unsigned char pass = 0x12;
	printf("Input byte is: %x\n", pass);
	unsigned char res;
	res = function(pass);
	printf("The result is %x\n",res); 
}
unsigned char function(unsigned char d)
{
	return ((d << 4) | (d >> 4));
}

          
Example:[10]

            Write a C program to get the status of nth bit of a number.
          

            #include <stdio.h>
unsigned int CheckBit(unsigned int ,unsigned int );
int main()
{
    unsigned int r = 11;
    r = CheckBit(r,1);
    printf("Bit %d status is %d\n", 1, r);
    return 0;
}
unsigned int CheckBit(unsigned int a,unsigned int x)
{
    if(((a >> x) & 1) == 1)
    {
        return 1;
    }else
    {
        return 0;
    }
}
          
Example:[11]

            Write a C program to set the 0th to 3rd bits of an integer.
          

            #include <stdio.h>
unsigned int SetBits(unsigned int ,unsigned int ,unsigned int);
int main()
{
    unsigned int r = 0;
    printf("Original %d\n", r);
    r = SetBits(r,0,3);
    printf("Result setbits is %d\n", r);
    return 0;
}
unsigned int SetBits(unsigned int a,unsigned int start,unsigned int end)
{
    int i;
    for(i = start;i <= end;i++)
    {
        a |= (1 << i);
    }
    return a;
}
          
Example:[12]

            Write a c program to clear the second bit of an integer from LSB.
          

            #include <stdio.h>
unsigned int ClearBit(unsigned int ,unsigned int );
unsigned int sum;
int main()
{
    unsigned int r = 11;
    printf("Original %d\n", r);
    r = ClearBit(r,1);
    printf("After clearing bit %d, result is %d\n", 1, r);
    return 0;
}
unsigned int ClearBit(unsigned int a,unsigned int x)
{
    return (a &= ~(1 << x));
}
          
Example:[13]

            Write a c program to toggle the second bit of an integer from LSB.
          

            #include <stdio.h>
unsigned int ToggleBit(unsigned int ,unsigned int );
unsigned int sum;
int main()
{
    unsigned int r = 11;
    printf("Original %d\n", r);
    r = ToggleBit(r,1);
    printf("After toggling bit %d, result is %d\n", 1, r);
    return 0;
}
unsigned int ToggleBit(unsigned int a,unsigned int x)
{
    return (a ^= (1 << x));
}
          
Example:[14]

            Write a c program function to set bit 1 for a given number.
          

            #include <stdio.h>
unsigned int SetBit(unsigned int ,unsigned int );
unsigned int sum;
int main()
{
    unsigned int r = 9;
    printf("Original %d\n", r);
    r = SetBit(r,1);
    printf("After setting bit %d, result is %d\n", 1, r);
    return 0;
}
unsigned int SetBit(unsigned int a,unsigned int x)
{
    return (a |= 1 << x);
}
          

 Search Links


 Popular C search MCQs


 Popular C search examples