Tuesday, September 2, 2014

ask user to input starting number and ending number with incremental number and display the numbers between them


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;
}

Sample Output


starting and ending number with incremental number in c language

No comments :

Post a Comment

Note: Only a member of this blog may post a comment.

Copyright 2017. All Rights Reserved. Privacy Policy / Terms And Conditions / Sitemap / Contact