/* write a c program to sum even number by getting input from user*/
#include <iostream.h>
int main(void)
{
int num = 1;
int sum = 0;
int upperlimit;
printf("Enter the upperlimit:");
scanf("%d", &upperlimit);
while( num <= upperlimit)
{
if(num % 2 == 0)
{
sum += num;
num += 1;
}
}
printf("The sum of the even num is 5d\n", sum);
return 0;
}
Above is my code to determine even number sum i dont know what is error in it i have try to remove the error but program execute well didn't display the required result....
void main() { int i=0; printf("Even numbers in: [0,20]"); while(i<=20) { printf("%d\t", i); i += 2; } }
#include<stdio.h>
main()
{
int i=1;
while(i<=20)
{
printf("%d",i);
i=i+2
}
}
Following for whole numbers....
If number mod 2 Then
add code for even number
Else
add code for odd number
End If
Something like this:
int i = 1;
while (i <= 100) {
System.out.print(i, ' ');
i+=2;
}
unsigned count = 0;unsigned num=1; do { std::cout << num << std::endl; num +=2; } while (++count<50);
It is too easy................ //Program to print numbers vertically #include<stdio.h> #include<conio.h> void main() { int last_no; int i; clrscr(); i=0; printf("Enter your last num.I will print 0 to that number"); scanf("%d",&last_no); printf("\n"); while(i>last_no) { printf("%d\n",i); i++; } getch(); } //poo.papule
CLS PRINT "PROGRAM: Print squares of all even numbers from 1 to 20" PRINT PRINT "number", "squared" PRINT FOR number% = 1 TO 20 IF number% MOD 2 = 0 THEN PRINT number%, number% * number% END IF NEXT END
#include<iostream> unsigned print_naturals (unsigned max) { unsigned num = 0; while (num<max) std::cout << ++num << ' '; std::cout << std::endl; } int main() { // print first 10 natural numbers: print_naturals (10); // print first 100 natural numbers: print_naturals (100); }
#include<stdio.h> main() { int a,i=1; printf("Enter max no"); scanf("%d",&a); do { printf("%d",i); i=i+2; }while(i<=a); }
int i=0; while (i++<n) { /*...*/ }
"While it is possible to use this program to print a book, it is highly recommended to print it with an actual publisher. You will get a much better deal and your book will look a lot more professional."
Write a c program to print the 100 to 1 nos
x as int = 0 while x < 50 x = x + 1 print x endwhile
unsigned count = 0;unsigned num=1; do { std::cout << num << std::endl; num +=2; } while (++count<50);
how do we use loops in c plus plus programing and what are basic differences between do,for and while loop
It is too easy................ //Program to print numbers vertically #include<stdio.h> #include<conio.h> void main() { int last_no; int i; clrscr(); i=0; printf("Enter your last num.I will print 0 to that number"); scanf("%d",&last_no); printf("\n"); while(i>last_no) { printf("%d\n",i); i++; } getch(); } //poo.papule
c the book mastering c
#include <iostream> using namespace std; int main() { int i=1; do { if( i%2 ) cout<<i<<" "; } while( ++i<100 ); cout<<endl<<endl; return(0); }
The following cases are all possible:- program without any for and while- program without for- program without while- program with both for and while
CLS PRINT "PROGRAM: Print squares of all even numbers from 1 to 20" PRINT PRINT "number", "squared" PRINT FOR number% = 1 TO 20 IF number% MOD 2 = 0 THEN PRINT number%, number% * number% END IF NEXT END
10 N = 1020 WHILE N < 5130 S = N^2 : Print N, S40 N = N + 150 WEND