Search This Blog

Friday, October 7, 2011

Write a program to read a natural num k and find the int num nearest to it which is divisable by 7–C Program

   1:  #include<stdio.h>
   2:  #include<conio.h>
   3:  void main()
   4:  {
   5:  int n,k,r;
   6:  printf("Enter the value of K:");
   7:  scanf("%d",&k);
   8:  r=k%7;
   9:  if(r<=3)
  10:  n=k-r;
  11:  else
  12:  n=k-r+7;
  13:  printf("The int no nearest to %d divisable by 7 is %d\n",k,n);
  14:  getch();
  15:  }

No comments:

Post a Comment