From 08015c2c5e4f1a3fd653eeff55db91fb8d01deb7 Mon Sep 17 00:00:00 2001 From: Yajushreshtha <97739937+Soyvor@users.noreply.github.com> Date: Mon, 14 Aug 2023 11:43:04 +0530 Subject: [PATCH] Update primeinrange.c for range issue Changes made: The num starts from 2, as 1 is not a prime number. Fixed the loop condition in the inner loop: i <= (num / 2) instead of i = (num / 2). Added a space after each prime number to improve readability. With these changes, the code should work as intended and print the prime numbers between 1 and 100. --- primeinrange.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/primeinrange.c b/primeinrange.c index a6ea431..311a3b4 100644 --- a/primeinrange.c +++ b/primeinrange.c @@ -1,25 +1,21 @@ -//C program to print prime numbers between 1 to 100. +#include -#include -void main() -{ - int num,i,count; - printf("Prime numbers b/w 1 to 100:"); +int main() { + int num, i, count; + printf("Prime numbers between 1 to 100:\n"); - for(num=1;num<=100;num++) - { - count=0; - for(i=2;i=(num/2);i++) - { - if(num%i==0) - { - count++; - break; - } + for (num = 2; num <= 100; num++) { + count = 0; + for (i = 2; i <= (num / 2); i++) { + if (num % i == 0) { + count++; + break; + } + } + if (count == 0 && num != 1) { + printf("%d ", num); + } } - if(count==0&&num!=1) - { - printf("%d",num); - } - } + + return 0; }