Showing posts with label accept number range and divisor. Show all posts
Showing posts with label accept number range and divisor. Show all posts

Friday, 24 August 2012

Find numbers between 100 to 200 which divisible by 7 and calculate number sum

Q. Write a C program to find the numbers and their sum between 100 to 200 which are divisible by 7.

or


Q. Write a C program to accept two randomly number from user and find out the numbers and their sum which are divisible by user entered number.  

Ans.

/*c program for find the number between 100 to 200 which are divisible by 7 and also calculate these number sum*/

#include<stdio.h>
#include<conio.h>
int main()
{

 int n1,n2,div,sum=0;
 printf("Note: First number must be less then to second number\n\n");
 printf("Enter first number: ");
 scanf("%d", &n1);
 printf("Enter second number: ");
 scanf("%d", &n2);
 printf("Enter divisor: ");
 scanf("%d", &div);
 printf("Numbers that are divisor by %d :\n",div);
 for(n1; n1<=n2; n1++)
 {
  if(n1%div==0)
  {
    printf("%d\t",n1);
    sum=sum+n1;
  }
 }
 printf("\nSum of numbers that are divisible by %d = %d",div,sum);
 getch();
 return 0;
}


/************Output************/


Output of find the number between 100 to 200 which are  divisible by 7 and these numbers sum
Screen shot find the number between 100 to 200 which are
 divisible by 7 and  calculate its number sum C program