answersLogoWhite

0


Best Answer

the following is C code, should work well enough. If not, you should get the general idea.

int counter;

for (int i=1;i<10;i++)

{

println("Enter a number: ");

cin << counter;

}

println("Total, %i", counter);

User Avatar

Wiki User

16y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

#include<stdio.h> void main() { int i,n,f1=0,f2=1;f,sum=0; printf("enmter the n value"); scanf("%d",&n); for(i=1;i<=n;i++) { f1=f2; f2=f; f=f1+f2; sum=sum+f; }//loop end }main end

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

Place the numbers in an array, then pass the array to a function that sums the squares. Note that you must check for overflow to ensure the returned value is valid.

long long sum_squares (const int a[], const int size, bool* overflow) { int i;

long long sum, product;

*overflow=false;

sum = 0;

for (i=0; i<size; ++i) {

if (*overflow = product_overflow (a[i], a[i])) break;

product = (long long) a[i] * a[i];

if (*overflow = sum_overflow (sum, product)) break;

sum += product;

}

return sum;

}

Example usage:

int main (void) {

bool overflow;

int a[] = {42, 39, 56, INT_MAX }; // a likely overflow

long long sum = sum_squares (a, 4, &overflow)

if (overflow) {

// sum is invalid

} else {

// sum is valid

}

return 0;

}

The overflow test functions have the following definitions:

#include<limits.h> // defines INT_MAX and LLONG_MAX

bool sum_overflow (const long long a, const long long b) {

return a > 0 && b > LLONG_MAX - a;

}

bool product_overflow (const long long a, const long long b) {

return a > 0 && b > LLONG_MAX / a;

}

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

for(int i = 0; i <= 10; ++i) {

}

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

int main()

{

for(int i = 1; i <= 10; i++)

std::cout << i << endl;

return 0;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Display numbers from 1 to 10 using for loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How 2 display 10 no in programming?

to display 10 numbers in C language we can use the while loop.... #include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int n=0; while(n&lt;=10) { printf("%d",n); //it will print the 10 numbers as output } getch(); }


Wright The numbers from 1 to 10 in descending order using loop?

int i; for (i=10; printf ("%d\n", i); i--);


Write an algorithm or draw a flowchart to display numbers from 100 down to 10?

n=100 loop until n = 9 print n n = n -1 end loop


How do you write a do while loop in visual basic to display the produc of even numbers between 1 and 10?

i=0 do if(i/2=0) msgbox(i) while(i&lt;=10) wend


Write a for next loop for even numbers beginning at 10 and ending at 50?

int i;for (i=10; i


Display odd number using for loop?

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 &lt; 50) { if(i%2 != 0) { System.out.println(i); } i++; } } }


How do you Draw a flowchart to display the highest of any 10 numbers entered?

The basic idea is as follows. Assume an array n(), of ten elements.* Set variable "highest" to the first number, n(1). * Set index "i" equal to 2. * Do the following in a loop: * If n(i) is greater than "highest", replace "highest" with n(i). * Increment i by 1. * Compare whether "i" is greater than 10. If it is, leave the loop. * Display variable "highest".


To print 5 45 345 2345 12345 in qbasic programming?

Oh, dude, to print those numbers in QBasic, you can use a simple loop. Just loop from 1 to 5 and print the numbers with spaces in between. It's like making a sandwich, but with numbers instead of bread and cheese. So, like, don't stress, just code it up and hit run. Easy peasy, right?


C plus plus program using for loop that prints all even numbers between and including 10 and 1000?

#include using std::cout;using std::endl;int main(){cout


Source code for loop in matlab?

% 1. Define starting and ending counter values (numerical values = numbers) starting=1; % for example, this for-loop is starting from number "1" ending=10; % for example, this for-loop is ending at number "10" % 2. Define what you want to do with the for-loop % For example, you can display ten times (on the Command Window) % "The quick brown fox jumps over the lazy dog." for id=starting:ending disp('The quick brown fox jumps over the lazy dog.'); end % 3. See: MATLAB Manual


Write a program using while loop?

//program to find the factorial value f any number using while loop #include&lt;stdio.h&gt; void main() { int i,n,fact=1; printf("Enter the number\n"); scanf("%d",&amp;n); i=n; while (i&gt;=1) { fact=fact*i; i--; } printf("The factorial value=%d",fact); } the above is a program for calculating tha factorial value of any number which is entered by the user


To print first 10 numbers in unix shell scripting using FOR loop?

The use of the "for" loop in many shell scripting languages to do what you want would be fairly confining. However, if you wanted to do that, you could, for example, do the following: for i in 1 2 3 4 5 6 7 8 9 10 do echo $i done