39. How can you remove duplicates in an array?
The following program will help you to remove duplicates from an array.
#include <stdio.h>
int main()
{
int n, a[100], b[100], calc = 0, i, j,count;
printf("Enter no. of elements in array.n");
scanf("%d", &n);
printf("Enter %d integersn", n);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i<n; i++)
{
for (j = 0; j<calc; j++)
{
if(a[i] == b[j])
break;
}
if (j== calc)
{
b[count] = a[i];
calc++;
}
}
printf("Array obtained after removing duplicate elements");
for (i = 0; i<calc; i++)
{
printf("%dn", b[i]);
}
return 0;
}
40. Can we compile a program without a main() function?
Yes, we can compile a program without main() function Using Macro.
E.g.
#include<studio.h>
#define abc main
int abc ()
{
printf("Hello World ");
return 0;
}
41. Write a program to get the higher and lower nibble of a byte
without using shi operator?
#include<stdio.h>
struct full_byte
{
char first : 4;
char second : 4;
};
union A
{
char x;
struct full_byte by;
};
main()
{
char c = 100;
union A a;
a.x = c;
printf("the two nibbles are: %d and %d\n", a.by.first, a.by.second);
}
42. How do you override a defined macro?
To override a defined macro we can use #ifdef and #undef preprocessors as follows:
#ifdef A
#undef A
#endif
#define A 10
If macro A is defined, it will be undefined using undef and then defined again using
define.
43. Write a C program to check if it is a palindrome number or not using a recursive method.
#include <stdio.h>
#include <conio.h>
int reverse(int num);
int isPalindrome(int num);
int main()
{
int num;
printf("Enter a number: ");
scanf("%d", &num);
if(isPalindrome(num) == 1)
{
printf("the given number is a palindrome");
}
else
{
printf("the given number is not a palindrome number");
}
return 0;
}
int isPalindrome(int num)
{
if(num == reverse(num))
{
return 1;
}
return 0;
}
int reverse(int num)
{
int rem;
static int sum=0;
if(num!=0){
rem=num%10;
sum=sum*10+rem;
reverse(num/10);
}
else
return sum;
return sum;
}
44. C program to check the given number format is in binary or not.
#include<stdio.h>
#include<conio.h>
int main() {
int j,num;
printf("Please enter a number :");
scanf("%d",&num);
while(num>0)
{
j=num%10;
if( j!=0 && j!=1 )
{
printf("num is not binary");
break;
}
num=num/10;
if(num==0)
{
printf("num is binary");
}
}
getch();
}
45. C Program to find a sum of digits of a number using recursion.
#include<stdio.h>
#include<conio.h>
int sumOfDigits(int num)
{
static int sum = 0;
int rem;
sum = sum + (num%10);
rem = num/10;
if(rem > 0)
{
sumOfDigits(rem);
}
return sum;
}
int main() {
int j,num;
printf("Please enter a number :");
scanf("%d",&num);
printf("sum of digits of the number = %d ",sumOfDigits(num));
getch();
}
46. Can you tell me how to check whether a linked list is circular?
Single Linked List
Circular Linked List
Algorithm to find whether the given linked list is circular
47. What is the use of a semicolon (;) at the end of every program statement?
function of datatype tool isCircular(firstgode){
48. How to call a function before main()?
49. Differentiate between the macros and the functions.
| Macros |
Functions |
|---|---|
| It is preprocessed rather than compiled. | It is compiled not preprocessed. |
| It is preprocessed rather than compiled. | Function checks for compilation errors. |
| Code length is increased. | Code length remains the same. |
| Macros are faster in execution. | Functions are a bit slower in execution. |
| Macros are useful when a small piece of code is used multiple times in a program. | Functions are helpful when a large piece of code is repeated a number of times. |

