Infosys
Company
Programming
Program
how do you increment a counter of for loop without using '+' (or '++') operator
Read Solution (Total 15)
-
- Simple x=x-(-1)
- 10 years agoHelpfull: Yes(23) No(0)
- #include
#include
void main()
{
int x;
printf("Enter the value");
scanf("%d",&x);
x=(x*2)-(x-1);
printf("%d",x);
}
OUTPUT:
If you will give any number it will increment it by one
Example if u give 4
It will give u output as 5 - 10 years agoHelpfull: Yes(20) No(4)
- printf("%d",x+=1);
- 10 years agoHelpfull: Yes(2) No(10)
- for( i = 1; i < n; i = i - ( - 1)
- 10 years agoHelpfull: Yes(2) No(0)
- a=printf(printf("%*d%d",x,1));
it will increment a by 1 - 10 years agoHelpfull: Yes(1) No(0)
- #include "stdio.h"
int Add(int x, int y){if (y == 0) return x; else return Add( x ^ y, (x & y) - 10 years agoHelpfull: Yes(1) No(0)
- In java:
By Using Enhanced for loop:
like we r having :
arr =new int[20];
then in enhanced for loop:
for(int i :arr){
//body
} - 10 years agoHelpfull: Yes(1) No(0)
- say you have the following code
for(int i=0;i0;i--){}
But if you do not even want to use increment or decrement operators then you can do it in the following way (its a C program):
#include
#include
int Add(int x, int y)
{
if (y == 0)
return x;
else
return Add( x ^ y, (x & y) - 10 years agoHelpfull: Yes(0) No(4)
- ++ operator
- 10 years agoHelpfull: Yes(0) No(2)
- for(i=o; i
- 10 years agoHelpfull: Yes(0) No(0)
- By Using Bitwise operators
- 9 years agoHelpfull: Yes(0) No(0)
- #include
#include
void main(){
int x;
for(x=0;x - 9 years agoHelpfull: Yes(0) No(0)
- for(int i=0;i
- 9 years agoHelpfull: Yes(0) No(0)
- Using left shift operator
- 6 years agoHelpfull: Yes(0) No(0)
- counter=counter+1;
- 3 years agoHelpfull: Yes(0) No(1)
Infosys Other Question