Tuesday 17 July 2018

LESSON 1 Prime number up to a limit C Programming

Prime number upto a limit

Here we importing to library (stdio.h)C Standard Input and Output Library for Input and Output operations. and conio is a c header file and not part of c standard library ,it is used MSDOS compilers to console Input/Output

here we have main function and declared n,i,j,k variables with integer properties
for storing the values to n we use %d followed by &n

Next is for loop section
for(i=2;i<n;i++) →means that i=2  to n , we have n value stored in int n variable , so if n is 10 then first it start from i=2 then check 2<10 ie is true so it add 1 to i  so i→3 then goto next for loop
and so on. for printing a variable i we use &d, then followed by i
At last we use getch() function to get a still screen 

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,k=0;
clrscr();
printf("Enter the limit");
scanf("%d",&n);
for(i=2;i<n;i++)
 {
  for(j=2;j<i;j++)
  {
  if(i%j==0)
  k++;
  }
  if(k>2)
  printf(" %d",i);
 }
 getch();
}

0 Comments:

Post a Comment

Facebook Twitter Delicious Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes