52.write a “Hello World” program in “c” without using a
semicolon?
53.Give a method to count the number of ones in a 32 bit number?
54.write a program that print itself even if the source file
is deleted?
55.Given an unsigned integer, find if the number is power of 2?
Answers were Sorted based on User's Feedback
Answer / tyutyjtytydf
#include<stdio.h>
#include<conio.h>
main()
{
if(puts("hello world"))
{}
}
Is This Answer Correct ? | 10 Yes | 0 No |
Answer / sainath
A small correction in the above answer. Use if condition as
shown below.
#include<stdio.h>
void main()
{
if(printf(%s, "Hello World"))
{
}
}
Answer for the last ques. i.e no. 55
unsigned int x;
if(x < 0) //Error checking only. Unsigned int shudn't
//have a negative value
return 0;
else
return !(x $ (x-1));
The logic here is, if we do bitwise 'and' with two
consecutive numbers, the greater of which is a power of 2
then the answer is 0.
Eg. 8 - 1000
8-1 - 0111
and & - 0000
Is This Answer Correct ? | 6 Yes | 0 No |
Answer / ss
#include<stdio.h>
void main(){
if(printf("Hello World"))
{
}
}
Is This Answer Correct ? | 6 Yes | 1 No |
Answer / amogh
53.
'num' is 32 bit integer
count=0;
for(;num!=0;count++)
num&=num-1;
55.
if(num&(num -1) == 0)
printf("%d is power of 2",num);
Is This Answer Correct ? | 5 Yes | 2 No |
Answer / hussain reddy
/* mypro.c*/
#include<stdio.h>
void main()
{
remove("mypro.c");
}
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / lokesh n. jaliminche
/*program to check if number is power of 2
#include <stdio.h>
unsigned int check_power(unsigned int value)
{
unsigned int count = 0;
while (value > 0) {
if ((value & 1) == 1)
count++;
value >>= 1;
}
return count;
}
int main()
{
unsigned int n, count;
printf("Enter the number \n");
scanf("%d",&n);
count=check_power(n);
if(count == 1)
{
printf("number is power of 2\n");
}
else
{
printf("number is not power of 2\n");
}
printf("set bits == %d",count);
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / lokesh n. jaliminche
#include <stdio.h>
unsigned int check_power(unsigned int value)
{
unsigned int count = 0;
while (value > 0) {
if ((value & 1) == 1)
count++;
value >>= 1;
}
return count;
}
int main()
{
unsigned int n, count;
printf("Enter the number \n");
scanf("%d",&n);
count=check_power(n);
if(count == 1)
{
printf("number is power of 2\n");
}
else
{
printf("number is not power of 2\n");
}
printf("set bits == %d",count);
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sankar kiran
#include<stdio.h>
#include<conio.h>
void main()
{
while(printf("Hello World"))
{
break;
}
getch();
}
Is This Answer Correct ? | 6 Yes | 8 No |
Answer / swastisundar bose
52.
#include<stdio.h>
void main(){
if("Hello World")
{
}
}
Is This Answer Correct ? | 17 Yes | 20 No |
Explain what will the preprocessor do for a program?
What is the output of the following program main();{printf ("chennai""superkings"}; a. Chennai b. superkings c. error d. Chennai superkings
Do you know what are the properties of union in c?
Explain zero based addressing.
difference between object file and executable file
What are linker error?
What will the preprocessor do for a program?
If fflush wont work, what can I use to flush input?
How can variables be characterized?
Explain what are run-time errors?
Total of how many functions are available in c?
Write a C program linear.c that creates a sequence of processes with a given length. By sequence it is meant that each created process has exactly one child. Let's look at some example outputs for the program. Here the entire process sequence consists of process 18181: Sara@dell:~/OSSS$ ./linear 1 Creating process sequence of length 1. 18181 begins the sequence. An example for a sequence of length three: Sara@dell:~/OSSS$ ./linear 3 Creating process sequence of length 3. 18233 begins the sequence. 18234 is child of 18233 18235 is child of 18234 ........ this is coad .... BUt i could not compleate it .....:( #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char *argv[]) { int N; pid_t pid; int cont; if (argc != 2) { printf("Wrong number of command-line parameters!\n"); return 1; } N = atoi(argv[1]); printf("Creating process sequence of length %d.\n",N); printf("%d begins the sequence.\n",getpid()); /* What I have to do next ?????? */ }