Write program c to print odd number from 1 to 100 using for loop
int main() {
printf(“Odd numbers from 1 to 100:\n”);
for (int i = 1; i <= 100; i++) {
if (i % 2 != 0) {
printf("%d\n", i);
}
}
return 0;
}
include
using namespace std;
int main(){
for(int i=1;i<=100;i++){
if(i%2!=0){
cout<<i<<endl;
}
}
return 0;
}
Here is the complete code in C to print odd numbers from 1 to 100 using a for loop.
#include <stdio.h>
int main() {
// Using a for loop to iterate from 1 to 100
for (int i = 1; i <= 100; i++) {
// Check if the current number is odd
if (i % 2 != 0) {
// If it's odd, print it
printf("%d\n", i);
}
}
return 0;
}
Thanks