printf("1 3 5 7 9\n");
#include<stdio.h> main() { int i=0,j=0,n; printf("Enter a number:"); scanf("%d",&n); printf("The first %d odd numbers are:-\n"); for(i=0;i<=n;i++) { if(j%2!=0) printf("%d\n"j); j=j+1; } }
Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.
It is actually quite easy to write a program in java to do this. The easiest way to do this that I can think of is to use the remainder operator (%) to test whether a number is odd or not. Here is a simple program that will print out all the odd numbers between 1 and 50. public class OddNumbers { public static void main(String[] args) { int i=1; while(i < 50) { if(i%2 != 0) { System.out.println(i); } i++; } } }
#include
seq 1 2 99
The first 20 odd numbers are: 13579111315171921232527293133353739.
Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.
#include<stdio.h> main() { int i=0,j=0,n; printf("Enter a number:"); scanf("%d",&n); printf("The first %d odd numbers are:-\n"); for(i=0;i<=n;i++) { if(j%2!=0) printf("%d\n"j); j=j+1; } }
The first 100 odd whole numbers are: 13579111315171921232527293133353739414345474951535557596163656769717375777981838587899193959799101103105107109111113115117119121123125127129131133135137139141143145147149151153155157159161163165167169171173175177179181183185187189191193195197199.
The first 85 odd numbers are: 1 3579111315171921232527293133353739414345474951535557596163656769717375777981838587899193959799101103105107109111113115117119121123125127129131133135137139141143145147149151153155157159161163165167169.
The sum of the first 15 odd numbers is 225.
The sum of the first 100 odd numbers is 10,000.
The sum of the first 300 odd numbers is 90,000
The sum of the first 40 odd numbers is 1,600.
The sum of the first 1,000 odd numbers is 1,000,000.
The sum of the first 50 odd numbers is 2,500.
The sum of the first 600 odd numbers is 360,000.