Posts

Showing posts with the label while

C Control Statements: While, and Do-While Loop Codes

Image
1. WAP to read a number from the user and whether a given number is prime or composite. #include <stdio.h> int main() {     int n, i = 2;     printf("Enter the number: ");     scanf("%d", &n);     while (i < n) {         if (n % i == 0) {             printf("Composite Number");             break;         }         i++;     }     if (i == n)         printf("Prime Number");     return 0; } 2. Write a program to read two numbers from the user (n1<n2) and display the natural numbers between them #include <stdio.h> int main() {     int n1, n2, i = 1;     printf("Enter the two numbers: ");     scanf("%d%d", &n1, &n2);          while (i <= (n2 - n1 - 1)) {         printf("The numbe...