Posts

Showing posts from November, 2023

C Language while loop "Print 1-3 9-16.....81-100" program with output

  # include <stdio.h> int main () { int start = 1 ; while (start <= 100 ) { printf ( "%d-" , start); if (start == 1 ) { start = 3 ; } else { start = start * start; } if (start <= 100 ) { printf ( "%d " , start); } } return 0 ; } Output: 1-3 9-16 81-100

C Language while loop "Print Even And Odd Number Between 1 to 10" program with output

  # include <stdio.h> int main () { int num = 1 ; printf ( "Even numbers between 1 and 10:\n" ); while (num <= 10 ) { if (num % 2 == 0 ) { printf ( "%d\n" , num); } num++; } num = 1 ; // Reset num to 1 printf ( "\nOdd numbers between 1 and 10:\n" ); while (num <= 10 ) { if (num % 2 != 0 ) { printf ( "%d\n" , num); } num++; } return 0 ; } Output: Even numbers between 1 and 10 : 2 4 6 8 10 Odd numbers between 1 and 10 : 1 3 5 7 9

C Language while loop "Sum of 1 to 10 Numbers" program with output

  # include <stdio.h> int main () { int num = 1 ; // Initialize a variable to store the current number int sum = 0 ; // Initialize a variable to store the sum while (num <= 10 ) { // Loop while num is less than or equal to 10 sum += num; // Add the current number to the sum num++; // Increment the current number } printf ( "The sum of numbers from 1 to 10 is: %d\n" , sum); return 0 ; } Output: The sum of numbers from 1 to 10 is : 55

C Language "Simple While Loop" program with output

  # include <stdio.h> int main () { int i = 1 ; // Initialize the counter to 1 while (i <= 5 ) { // Check if the counter is less than or equal to 5 printf ( "%d\n" , i); // Print the current value of i i++; // Increment the counter by 1 } return 0 ; } Output: 1 2 3 4 5