Hey....Help me in this one please... I have to encode something that the output will come out as example....10, 8, 6, 4, 2, 0..... please help me what I did wrong....Thanks ...and I like to thank Narue too...for helping me in my last problem....I have to do this without using my c said sir :'(

#include<stdio.h>
main()
{
int a[100];
int b=0;
int c=2;
int d;
printf("Write the Number:");
scanf("%d",&d);
//Subtract d to c
while(a>=0)
{
a[b]=d-c;
}
printf ( "The Answer is %d\n", a[b]); 
return 0;
}

So a number is taken from a user, and 2 is subtracted from it until it's 0? Why do you have an array or a[100]? Do you need to save each number? Just try to think about it.

Problem:

  1. You're given a number.
  2. You take two from this number,
  3. you print it,
  4. you check that it's above 0
  5. and repeat.

Solution:

  1. Done!
  2. Change to c-=2;
  3. To do (put a printf in the while loop)
  4. I think the >= should simply be a > in the while loop.
  5. done.

>> I have to do this without using my c said sir
I think the aforementioned 'sir' might appreciate that.

So my answer should be in this form??? Heheheh Sorry if I did it wrong cause I'm still a beginner and I want to learn and willing to hear from you Thanks....

#include<stdio.h>
main()
{
int a;
int c=2;
int d;
printf("Write the Number:");
scanf("%d",&d);
//Subtract d to c
while(a>0)
{
c-=2;
printf("\n %d ",c);
}
printf ( "The Answer is %d\n", a); 
return 0;

Please use code tags and properly format your code. We'll give you a little leeway to learn how the forum works, but after a while (10 posts in general, but less if we feel you're intentionally refusing) you'll begin receiving infractions for breaking Daniweb's rules if you habitually fail to use code tags.

I think you have all your numbers mixed up... you're scanning d, a is used as the while loop control, c has 2 being subtracted from it, and then you're printing a. You only need one variable. So instead read in a, use a cor while( a>0 ), say a -= 2;, and finally print a.

O.K. I got it and does my coding look correct to you???? Narue Sorry..... I'll Try to code these this before I put them in my threads..... and thank you very much twomers I appreaciate your help.....

#include<stdio.h>
#include<conio.h>
main()
{
clrscr ();
int a,c=2;
printf("Write the Number:");
scanf("%d",&a);
//Subtract 2 from any number
while(a>0)
{
a-=c;
printf("\n\n\n	 %d",a);
}
return 0;
getch;
}
This question has already been answered. Start a new discussion instead.