Sum of two numbers without using arithmetic operators
Ex:int a=10;int b=10;int sum=a+b;without using "+" operator calculate sum
Write a program to find the binary form for the given charcter input.Eg:- for 'a' ascii value is 65 and its binary form is 1000001.
This seems a rather pointless endeavour, as the binary representation of, say, 'a' will vary with the execution character set. For example, in EBCDIC, 'a' has a value...
Here is a simple code which will just get each bit of the char by AND operationint main (){ char a; int i,j; printf("Enter a charn"); sc...
Is there any relation between a[i] and i[a] while using arrays..Can anyone help me with this....
Bath a[i] and i[a] are same.....the variable name 'a' contains the basic address of the array.so a[i] means base address + index 'i' and also i[a] means base address + index 'i'
there is no difference in compilation perspective
both are internally converted as *(a+i) or *(i+a) which means the same thing
What will be the code in C to get the following output?A b C d e f g f e d C b aa b C d e f f e d C b aa b C d e e d C b aa b C d d C b aa b C C b aa b b aa a
Code
#include <iostream> #include <fstream> void display_sequence2(int depth) { int output_count = 0; for (int count = depth - 1; count >= 0; --count) { for (int index = 0; index <= count; ++index) for (int index = (count == (depth - 1)) ? count - 1 : count; index >= 0; --index) { if (index > 0) } } } int main() { display_sequence2(7); }
Is it possible to write a C program without semicolons?
Code
#include<stdio.h><br /><br />void main()<br /><br /> {<br /><br /> if(printf("no semicolon"))<br /><br /> {}<br /><br /> }
Addition of 2 no without using semicolon:
void main(){ while( !printf("sum value=%d",10+20) ) { } }
or,
void main(){ if( printf("sum value=%d",10+20) ) { } }
or,
void main(){ switch( printf("sum value=%d",10+20) ) { } }
What is the relation between array name and an element number.
Array name is the base address of the aaray. By using this base address we can refer to the array elements. that is a[0] means "base address + 0th" element. that is array element number is the distence from the base address to the specified data
The relationship between an array element and the elements index number is as follows. 1. The array name by itself is a constant pointer to the first element of the a...
What is the difference between structure & union?
How can we multiply this a*b without using "*" operator?
All the members of the structure can be accessed at once,where as in an union only one member can be used at a time. Another important difference is in the size allocated to a structure and an union. ...
If the only thing is not to use '*' operator then I would prefer below method: A: mutiplier B: multilpicand mul: multiplication mul= A/(1/B); Sample C code: "c #include int mai...
C program to count numbers of positive and negative numbers
Write a C program using arrays to count the numbers of positive and negative numbers which accepts the inputs as "size of the array" & "elements of the array" and outputs as "number of negative numbers in an array are" & "numbers of positive numbers in an array are" ?
#include <stdio.h>main(){ int a[] = { 1,-3,-5,-4,-9,2,8}; int len,i,val; int npos=0, nneg=0; len = sizeof(a)/sizeof(a[0]); printf(&quo...
#include<conio.h>#include<stdio.h>void main() { int *arr,num,i=0,pos=0,neg=0; clrscr(); prin...
The o/p will be 11 30. Can somebody tell me how?
The variable a is incremented by one only after completing
the statement b=a++ + 20;
So after executing the statement b=a++ + 20 the variable b will have the value 30.
Then the value of variable a is incremented that is why the out put is 11 30.
a = 11 b=30
What is far pointer and where should we use it?
C has no "far" pointers, it only has pointers.Some (generally ancient) compilers, notably for DOS, did offer near, far, and huge pointers. This was due to how DOS managed memory.Basica...
Use Of Far Pointer..........Each program has its own data and code segments which is allocated by the compiler.The normal pointer or near pointer can address locations which are in its ...
0 1 2 0
It proceeds like thisfun(3)fun(2)fun(1)fun(0)fun(-1)printf("%d",n)(Here n is 0)fun(-1)printf("%d",n)(Here n is 1)fun(0)printf("%d",n)(Here n is 2)fun(1)fun(0)printf("...
The out will be just like 3 2 1 0 2 1 0 1 0 0... not sureThis is a recursive function with 2 recursive calls one at line 13 and other in at line 15.The variable 'a' initial...
Break statement can be simulated by using 1. Go to 2. Return 3. Exit 4. Both return and exit
The Break statement can be simulated by using the "goto" statements.The exit statement is used for exiting the program and the return statement is for returning to the calling function. So b...
The ans is goto
In c language there is no modifiers like protected,public,private......these modifiers are in c++ language.......
In c language the structure fields are public by default that is they can used by any structre instance variabes....
By defalt the members of a structure are public
Write a C program to find biggest of 4 numbers without using relational operators?
// Find The Largest Of 4 numbers (Only For Positive Numbers) #include
n1,n2,n3,n4
if(n1-n2) && (n1-n3) && (n1-n4)
How we print alphabets using while loop?
#include<stdio.h> #include<conio.h> void main() { int alphabet=65;  ...
Printing numbers from 1 to 100 without using condition checking.
void main() { int count=100,i=1; while(count--) printf(" %d",i++); }
Just came up with another solution. It is a 1-liner:cout << "1 2 3 4 5 6 7 ...........................99 100";very simple.
How to reverse a string using array?
Header files contains pre-compiled functions.The similar functions are grouped into same header files. These functions can be used by our programs using the icludederivative. So we can use these heade...
Hi,
To include the functions which are not changed and which are useful for other functions For ex: I/O functions are included in the header file as they are not a part of your complier. So, we use header files to make our program easier to write
// Fibnocci Series Using Recursion #include<stdio.h> #include<conio.h> void fun(int,int); int num; void main() { clrscr(); p...
// Fibnocci Series Using Recursion #include #include void fun(int,int); int num; void main() { clrscr(); printf("Enter The Limit :"); scanf("%d",&num); printf("The Fibnocci Series Up To %d Is...
How to find a given number is armstrong number or not in "c".?
void main() { int num1,num2,sum=0,rem; printf("Enter The Number :"); scanf("%d",&num1); num2=num1; while(num2>0) { rem=num2%10; sum+=rem*rem*rem; num...
The check should should be
while ( n>=1) and not (n>=0)
The cotrol enters into an infinite while loop.
How to type a string without using printf function?
Using Video Memory We can write a string into the screen.....that is the string is directly placed into the Video memory...ExampleVideo Memory Address : 0xb0008000 pgm: void main() { int i=0; ...
use write system call
write (1 , "XXXXXXXXXXXXXXX" , strlen("XXXXXXXXXXXXXXX" ));
Between a long pointer and a char pointer , which one consumes more memory? Explain
As a general rule of thumb, object pointers (as opposed to function pointers) will typically be the same size, as the relevant information - memory address - requires the same size regardless of type....
I am sorry the 2 part of the above answer is wrong.....
I confused long pointer with far pointer
SIze of long pointer and char pointer will be the same
When function say abc() calls another function say xyz(), what happens in stack?
before the control transfered into the called fucntion(ie. xyz()), the values in some of the registers copied into the stack(registers are : BP,SP,CS,IP,falg).also the values of the local variabl...
when the function 'abc()' calls another function 'xyz()' then first of all, current status of execution is stored in the STACK i.e. the address of current statement (Which lies in Code segment), then ...
Assuming i contains the number we wish to evaluate...
char *oddeven[] = {"even", "odd"};
printf("number is %sn",oddeven[i%2]);
modulus operator can be used.
if (i%2)
printf("Even");
else
printf("Odd");
Regards,
Geetha B
Far pointers are mainly used for 32 bit addressing that is the segment offset addressing. Normal pointers can onLy access the memory locations which is allocated by the compiler for that program. Far...
When the function is present out side the segment, it requires base address and offsetaddress. To access the function, the base and offset addersses are required to specify. This is like the far jum...
What is the difference between #include <file> and #include “file”?
When writing your C program, you can include files in two ways. The first way is to surround the file you want to include with the angled brackets < and >. This method of inclusion tells the preprocessor to look for the file in the predefined default location. This predefined default location...
if you used #include" filename.h" for including header files then the compiler will check only in the current directory.but if you used #include<filename.h> for including header files then the compiler will checks all directories specified in the directory options of turbo c
hi,
#include
#include"file" searches the file in the current working directory as wel as in the specified list of directories.
How do you redirect a standard stream?
Most operating systems, including dos, provide a means to redirect program input and output to and from different devices. This means that rather than your program output (stdout) going to the screen; it can be redirected to a file or printer port. Similarly, your program’s input (stdin) can come from...
Another way to do this is to use the dup system call.
By using the operators "<" and ">" we can redirect the standard input and out streams.
example : d:> jinto.exe > outputredirected
d:> jinto.exe < inputredirected
Editorial / Best Answer
Answered by: jintojos
View all answers by jintojos
Member Since May-2008 | Answered On : Jul 17th, 2008
void main()
{
int a=10,b=20;
while(b--) a++;
printf("Sum is :%d",a);
}
For two positive numbers:
int main(){
int a = 10;
int b = 10;
printf("%d",a ^ b | ((a & b)<< 1));
return 0;
}