1.What's the "condition" so that the following code snippet prints both HelloWorld! ?
if "condition"
printf("Hello");
else
printf("World");
Answer :if (!printf(“Hello”))
2. Write a C program that will print 1 to N, one line each, on the screen (stdout) where N is an int variable. " Should not use while, for, do-while loops, goto statement, setjmp (), longjmp (), recursion, if, if-else, assert (), switch (), goto, continue statement and not use N prinf () statment" For example,
if N =5 then the output should be like,
1 2 3 4 5
Answer :Here I gave the solution to print up to 50. if u want to make this program to print N integers you have to initialize the array Numbers with 1 to 32767.
3.Given a singly-linked, find out the mid point of a single linked list in a single parse of the list. Assume the program would be loaded in read-only memory, so no manipulation of the list is allowed.?
Answer :
Declared two structure pointers, both should point to Linked List.
Travel the Linked List till the lost node using first pointer
Increment the first pointer by 2 and increment the second pointer by 1.
When the first pointer reaches the end node, the second pointer pointing the middle element of the list.
Nowprint the data, which is pointed by the second pointer.
void find_mid_element(struct Link_List *p)
{
struct Link_List *first,*second;
first=second=p;
while(first->Next!=NULL)
{
if(first->Next->Next!=NULL)
first=first->Next->Next;
else
first=first->Next;
second=second->Next;
}
printf("\nThe Middle Element = %d\n",second->Data);
}
4.Write a C program to find the Biggest of three integers, without using any of the comparison operators.
Answer :
Logic :
1. Read Three Numbers,
2. Find Out The Difference Between The First Two Numbers
3. Add Two Numbers Along With The Difference.
4. Divide The Sum By Two, This Will Gives The Bigger Number.
5. Now Find The Difference Between The Bigger Number & The Third Number.
6. Repeat The Step 3,4.
7. Print The Biggest Number.
#include<stdio.h>
#include<math.h>
int main()
{
int First_Num,Second_Num,Third_Num,Biggest;
unsigned int Difference;
printf("Enter The First Number Is:");
scanf("%d",&First_Num);
printf("Enter The Second Number Is :");
scanf("%d",&Second_Num);
printf("Enter The Third Number Is:");
scanf("%d",&Third_Num);
Difference=abs(First_Num - Second_Num);
Biggest=((First_Num+Second_Num+Difference)/2);
Difference=abs(Biggest - Third_Num);
printf("The Biggest Number Is:%d", (Biggest + Third_Num + Difference) /2);