What change is required in the following program so that its output becomes 3,6,11,20,37,......1034?

Code
  1. #include<stdio.h>

  2. #include<math.h>

  3. int main()

  4. {

  5. int a=1,r=2,i;

  6. for (i=0;i<=10;i++)

  7. printf(",%d ", a * pow(r,i));

  8. return 0;

  9. }
Copyright GeekInterview.com

Questions by Swati Goel

Showing Answers 1 - 9 of 9 Answers

prakash pankaj

  • Dec 1st, 2012
 

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. int main()

  4. {

  5. int r=2,i,a;

  6. for(i=1,a=1;a<10,i<10;a++,i++)

  7. {

  8. printf("%d",(a+pow(r,i));

  9. }

  10. return 0;

  11. }

  Was this answer useful?  Yes

Code
  1. #include<iostream>

  2. using namespace std;

  3. int main()

  4. {

  5. int temp=3;

  6. for(int i=0;i<10;i++){

  7.         cout<<temp<<endl;

  8.         temp=temp*2-i;

  9.  

  10.  

  11. }

  12.  

  13.     return 0;

  14. }

  Was this answer useful?  Yes

nira

  • Jul 1st, 2014
 

Much easier approach,
this is a logic question, not programming

Code
  1.    

  2.     #include<stdio.h>

  3.     #include<math.h>

  4.     int main()

  5.     {

  6.     int a=1,r=2,i;

  7.     for (i=0;i<=10;i++)

  8.     printf(",%d ", a * pow(r,i) + i);

  9.     return 0;

  10.     }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions