0% found this document useful (0 votes)
10 views1 page

M

Uploaded by

mohanavijayan677
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

M

Uploaded by

mohanavijayan677
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h>

int main() {
char str[100];
int numbers[50]; // Array to store numbers
int i = 0, j = 0, num = 0, isPrime, count = 0;

// Input the string of numbers


printf("Enter a string of numbers separated by spaces: ");
scanf("%[^\n]", str); // Read the entire line of input

// Parse the string to extract numbers


for (i = 0; str[i] != '\0'; i++) {
if (str[i] >= '0' && str[i] <= '9') {
num = num * 10 + (str[i] - '0'); // Build the number
} else if (str[i] == ' ' || str[i] == '\0') {
numbers[count++] = num; // Store the number
num = 0; // Reset num for the next number
}
}
if (num != 0) { // Store the last number
numbers[count++] = num;
}

// Check and print non-prime numbers


printf("Non-prime numbers: ");
for (i = 0; i < count; i++) {
int currentNum = numbers[i];
if (currentNum < 2) {
printf("%d ", currentNum); // 0 and 1 are non-prime
} else {
isPrime = 1; // Assume the number is prime
for (j = 2; j <= currentNum / 2; j++) {
if (currentNum % j == 0) {
isPrime = 0; // Found a divisor
break;
}
}
if (!isPrime) {
printf("%d ", currentNum); // Print non-prime number
}
}
}
printf("\n");

return 0;
}

You might also like