I need a program which when a user types three different random numbers, the program only calculates and summarizes the sum of the positive ones and gives me an answer!

Thank you!

0 votes

nsum = 0

nums = tuple(map(lambda n: float(n), input('Input 3 numbers:\n').split(' ')))for item in nums:

if item > 0:

nsum += itemprint(nsum)

You can put more than 3 numbers. Also, type them in with a space in between, like this:

1 -20 3

0 votes

the following program is written in C:

#include <stdio.h>

int main()

{

int a, b, c, s=0;

printf("enter any three numbers: ");

scanf("%d%d%d", &a, &b, &c);

if(a>0)

s=s+a;

if(b>0)

s=s+b;

if(c>0)

s=s+c;

printf("%d", s);

}

#include <stdio.h>

int main()

{

int a, b, c, s=0;

printf("enter any three numbers: ");

scanf("%d%d%d", &a, &b, &c);

if(a>0)

s=s+a;

if(b>0)

s=s+b;

if(c>0)

s=s+c;

printf("%d", s);

}

0 votes

#include <iostream>

using namespace std;

double somma (double a, double b, double c)

{

double sum = 0;

if (a > 0) sum += a;

if (b > 0) sum += b;

if (c > 0) sum += c;

return sum;

}

int main() {

double x, y, z;

cout << "Inserire 3 numeri : ";

cin >> x >> y >> z;

cout << "La somma dei numeri positivi รจ : " << somma(x,y,z);

}

using namespace std;

double somma (double a, double b, double c)

{

double sum = 0;

if (a > 0) sum += a;

if (b > 0) sum += b;

if (c > 0) sum += c;

return sum;

}

int main() {

double x, y, z;

cout << "Inserire 3 numeri : ";

cin >> x >> y >> z;

cout << "La somma dei numeri positivi รจ : " << somma(x,y,z);

}

0 votes

#include <stdio.h>

int main(){

int num1, num2, num3, sum = 0;

printf("Enter three numbers: ");

scanf("%d %d %d", &num1, &num2, &num3);

if(num1>0)

sum += num1;

if(num2>0)

sum += num2;

if(num3>0)

sum += num3;

printf("Sum of numbers entered = %d", sum);

return 0;

}

int main(){

int num1, num2, num3, sum = 0;

printf("Enter three numbers: ");

scanf("%d %d %d", &num1, &num2, &num3);

if(num1>0)

sum += num1;

if(num2>0)

sum += num2;

if(num3>0)

sum += num3;

printf("Sum of numbers entered = %d", sum);

return 0;

}

0 votes

This is written in c using functins, hope it helps:

#include <stdio.h>

int add(int x,int y,int z);

int main()

{

int x,y,z,sum;

printf("Enter 3 no's: ");

scanf("%d %d %d", &x,&y,&z);

sum=add(x,y,z);

printf("Addition of +ve no's is:%d",sum);

return 0;

}

int add(int x,int y,int z)

{

int sum,res;

if(x>0)

sum+=x;

if(y>0)

sum+=y;

if(z>0)

sum+=z;

return sum;

}

#include <stdio.h>

int add(int x,int y,int z);

int main()

{

int x,y,z,sum;

printf("Enter 3 no's: ");

scanf("%d %d %d", &x,&y,&z);

sum=add(x,y,z);

printf("Addition of +ve no's is:%d",sum);

return 0;

}

int add(int x,int y,int z)

{

int sum,res;

if(x>0)

sum+=x;

if(y>0)

sum+=y;

if(z>0)

sum+=z;

return sum;

}

0 votes

#include<iostream>

using namespace std;

int main()

{

int i,a[3],s=0;

for(i=0;i<3;i++)

{

cin>>a[i];

}

for(i=0;i<3;i++)

{

if(a[i]>0)

{

s+=a[i];

}

}

cout<<s;

}

using namespace std;

int main()

{

int i,a[3],s=0;

for(i=0;i<3;i++)

{

cin>>a[i];

}

for(i=0;i<3;i++)

{

if(a[i]>0)

{

s+=a[i];

}

}

cout<<s;

}

...