C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++ tutorials and pdf

since the program is to find odd numbers from 1 to 100 , we use for loop. Here i=2 is the initialization,i<100 is the condition and i=i+2 is the increment operation i.e it will increment the condition. Here i=i+2 is to find for odd numbers.So all the numbers b/w 1 and 100 will get printed .

/*Find the even no and their sum*/ #include main() { int i=1,n,s=0; printf("enter the value of n\n"); scanf("%d",&n); while(i<=n) { if(i%2==0) { printf(" %d ",i); s=s+i; } i++; } printf("\n"); printf("s=%d\n",s); }

if you want to take input i also user than not declare i=0, also take value of i from user same taken from n,but carefully at user input end I is less than N.

It means if d value of i is divided by 2 and if d remainder is equal to 0 den the value of i is an even number!! for eg. assume that if i=2 den from d if condition it is divisible by 2 n d remainder is 0 so the value of i wud b printd as an even number

## 19 comments:

i dont understand the solutions pliiz help.....what does "%d"/n",i mean?

prinf function is formated function.

"%d\n" is format. Here

%d represent decimal number or integer type number

\n is new line character.

We have used %d since variable is integer type variable and in the output %d will be replaced by value i.

If you have still doubt the you are welcome.

where use i value

what does i=i+2

what does i+2?

since the program is to find odd numbers from 1 to 100 , we use for loop. Here i=2 is the initialization,i<100 is the condition and i=i+2 is the increment operation i.e it will increment the condition. Here i=i+2 is to find for odd numbers.So all the numbers b/w 1 and 100 will get printed .

sorry odd numbers will get printed.

Initially i value is 1 so loop add 1+2 = 3

sir if user prints two unknown number and we have to find all the odd numbers between them then what should we do????

/*Find the even no and their sum*/

#include

main()

{

int i=1,n,s=0;

printf("enter the value of n\n");

scanf("%d",&n);

while(i<=n)

{

if(i%2==0)

{

printf(" %d ",i);

s=s+i;

}

i++;

}

printf("\n");

printf("s=%d\n",s);

}

if you want to take input i also user than not declare i=0, also take value of i from user same taken from n,but carefully at user input end I is less than N.

how make this program with for loop? please code

how make this program with for loop? please code

Well explained

in line number 14 you have stated if (i%2==0), what does it mean?

It means if d value of i is divided by 2 and if d remainder is equal to 0 den the value of i is an even number!! for eg. assume that if i=2 den from d if condition it is divisible by 2 n d remainder is 0 so the value of i wud b printd as an even number

why the program is coming when the void is placed in it ????????

one more way of doing is

#include

int main()

{

int i;

int a;

for(i=0;i<50;i++)

{

a=(2*i)+1;

printf("%d",a);

}

}

one more way of doing is

#include

int main()

{

int i;

int a;

for(i=0;i<50;i++)

{

a=(2*i)+1;

printf("%d",a);

}

}

Post a Comment