TRENDING NEWS

POPULAR NEWS

How Do I Find Sum Of Integers Numbers In C Code

Write a pascal programming to find the average of 3 numbers?

var b,c,d:integer;
a:real;
begin
readln(b);
readln(c);
readln(d);
a:=(b+c+d)/3;
writeln(a:6:2);
readln;
end.


So, let me explain this program a little bit, so maybe you can get it... or else you'll never learn. So we declared b,c,d as three integer numbers and a as a real one (because a is the number that represent the average, and the average may not be a natural number). We read the numbers (the three lines with readln), we tell the program that the a should get the value of (b+c+d)/3 and then we tell the program to write that value. The :6:2 means that the number wrote will have maximum 6 spaces before the dot, and maximum 2 after the dot. So the maximum number would be 999999.99;

Well, I hope I helped!

How to write a program using while loop to find the sum of integers 73 through 415 inclusive?

a = 73;
b = 415;
sum = 0;
while ( a <= b) {
sum = sum + a;
a++;
}
print "Sum is: ", sum;

Written in generic code, since you did not specify a programming language.

How can I write C++ code that prints the sum, product, and average of three integers with two decimal place precision?

Source Code:#include#includeusing namespace std;int main(){int a,b,c;cout<<"Enter the values for a,b,c:"<>a>>b>>c;float sum,average,product;sum = a+b+c;average = (sum)/3;product = a*b*c;cout<

Program that reads a set of integers, and then finds and prints the sum of the even and odd integers C++?

This is what I have and for the life of me cannot get it to come out right any help is appreciated

#include
#include

using namespace std;

int main()
{
int num=0, even=0, odd=0;

cout << "Enter the list of integers" << endl;
cin >> num;


{
if(num % 2 == 0) // Checking for the even number.
even = even + num; // If even then increment the value of even by the number itself
else if(num % 2 != 0) // Checking for the odd number.
odd = odd + num; // If odd then increment the value of odd by the number itself

cin >> num;
;
}
{
cout << "The sum of the even integers is: " << even << endl;
cout << "The sum of the odd integers is: " << odd << endl;
}

return 0;
}

Write C program that converts string to an integers and sums these values and prints the result at the screen?

What you've written is C++, not C. If that's the assignment, then add to your includes to get the prototype for atoi().

If you are supposed to find the integer substrings of something like "35 40 28 12" as part of the assignment, then maybe you should look at sscanf() (in for C++ or for C.)

If you are supposed to get the strings from the console, then you need to write code to read strings one at a time. You can either store them in an array, or do the conversion and sum in the input loop.

Here's a loop that will convert and sum strings from an C-style strings:

/* At the top of the source file: */
#include ... or for C++
#include ... or for C++
...
/* At the top of main()...C needs all declarations at the beginning of a block */
char* string[] = {"35", "40", "28", "12" );
int nstrings = 4;
int i, sum;
...
/* In the body of main() */
for (i=0, sum=0; i{ sum += atoi(strings[i]); }
printf("The sum is %d\n", sum);

How do I write a C program to add two floating point numbers?

It’s actually really hard to get this single line of C wrong if you have done primary school arithmetic.Give it a go.Write a main function, then put your single line inside it. Use printf to display the answer. You’ll need to lookup the conversion for ‘float’

TRENDING NEWS