Problem
write a program which prompts the user for 3 inputs (shown below - determines how and what to count). The user’s answers should be stored in variables. Your counting program should make use of the for loop.- Ask the user to enter beginning number to start counting from
- Ask the user to enter ending number to stop counting at
- and also ask the user to enter the incremental number
Solution - Code
#include<stdio.h>int main()
{
int i,x,y,z;
printf("Enter beginning and ending number: ");
scanf("%d%d",&x,&z);
printf("Enter increment = ");
scanf("%d",&y);
for(i=x;i<=z;i=i+y)
{
printf("%d\n",i);
}
system("pause");
return 0;
}
No comments :
Post a Comment
Note: Only a member of this blog may post a comment.