Showing posts with label Exercise 5. Show all posts
Showing posts with label Exercise 5. Show all posts

Sunday, 23 April 2023

Exercise 5-To demonstrate use of nested loops

SET A

1. Write a program to display all prime numbers between x and y.

#include<stdio.h>
#include<conio.h>
void main()
{
 int x,y,i,flag,j;
 clrscr();
 printf("\nEnter two Numbers:");
 scanf("%d%d",&x,&y);
 printf("\nPrime numbers between %d and %d is  ",x,y);
 for(i=x;i<y;i++)
    {
     flag=0;
     for(j=2;j<i;j++)
    {
     if(i%j==0)
        flag=1;
    }
     if(flag==0)
       printf("\n%d",i);
    }
 getch();
}

OUTPUT:

Enter two Numbers:1                                                            
20                                                                             
                                                                               
Prime numbers between 1 and 20 is                                              
1                                                                              
2                                                                              
3                                                                              
5                                                                              
7                                                                              
11
13
17
19

Questions

  Exercise 1 Set A . Apply all the three program development steps for the following examples.  1. Accept dimensions of a cylinder and p...