Skip to main content

Posts

Recent posts

What will be output of following c code while loop increment decrement?

  Output of following c code while loop                                increment decrement? #include<stdio.h> int main(){     int i,j;     i=j=2,3;     while(--i&&j++)          printf("%d %d",i,j);     return 0; } Output: 13 Explanation : Initial value of variable  i = 2 j = 2 Consider the while condition : --i && j++ In first iteration:  --i && j++ = 1 && 2 //In c any non-zero number represents true. = 1 (True) So while loop condition is true. Hence printf function will print value of i = 1 and j = 3 (Due to post increment operator) In second iteration: --i && j++ = 0 && 3  //In c zero represents false = 0  //False So while loop condition is false. Hence program control will come out of the for loop. Join us on Facebook:  Click Here  

What will be output of following c code using while loop ?

  Output of c code using while loop #include<stdio.h> extern int x; int main(){     do{         do{              printf("%o",x);          }          while(!-2);     }     while(0);     return 0; } int x=8; Output: 10 Explanation: Here variable x is extern type. So it will search the definition of variable x. which is present at the end of the code. So value of variable x =8 There are two do-while loops in the above code.  AS we know do-while executes at least one time even that condition is false.  So program control will reach  at printf statement at it will print octal number 10 which is equal to decimal number 8.  Note: %o is used to print the number in octal format.  In inner do- while loop while condition is ! -2 = 0 In C zero means false.  Hence program control will come out of the inner do-while l...

A gold smith sells a one gram of 24 carat gold for Rs 5500 .WAP to read the weight of gold in grams and calculate its cost in 18,20,22, and 24 carat in c++ ?

  The weight of gold in grams and calculate its cost in 18,20,22, and 24 carat in c++. #include<iostream.h> #include<conio.h> void main() { float weight,carat,carat18,carat20,carat22,carat24; clrscr(); cout<<endl<<"Enter the weight of gold in grams :"; cin>>weight; carat=5500/24.0; carat18=carat*18*weight; carat20=carat*20*weight; carat22=carat*22*weight; carat24=5500*weight; cout<<endl<<"Cost in 18 carats = " <<carat18; cout<<endl<<"Cost in 20 carats = " <<carat20; cout<<endl<<"Cost in 22 carats = " <<carat22; cout<<endl<<"Cost in 24 carats = " <<carat24; getch(); } Join us on Facebook:  Click Here  

Write a program to read the five digit number and find the reverse in c++ ?

  The five digit number and find the reverse in c++   num = 12345 rev=54321 #include<iostream.h> #include<conio.h> void main() { long num,rev; clrscr(); //read the five -digit number  cout<<endl<<"Enter the five digit number :"; cin>>num; //find the reverse  rev=num%10; num=num/10; rev=rev*10+num%10; num=num/10; rev=rev*10+num%10; num=num/10; rev=rev*10+num; cout<<endl<<"Reverse  = " <<rev; getch(); } Join us on Facebook:  Click Here