What's new

Closed Help !!!

Status
Not open for further replies.

Koykoy200078

Forum Veteran
Joined
Sep 11, 2016
Posts
1,765
Reaction
696
Points
629
Age
23
help po mga master na programmer jan, bagohan pa po lamang ako about ni .C Language my pinagawa po saamin ang teacher namin na " Input 5 Numbers and Display the 5 numbers with Sum " using the loops po, ito po pala yung full code ko pero isa lang po ang lumabas ayaw mag display ng 5 numbers

"user input 5 and display 5 numbers with the sum" yan po

#include <stdio.h>
int main()
{
int n, i, sum = 0;

printf("Enter a positive integer: ");
scanf("%d",&n);

for(i=1; i <= n; ++i)
{
sum += i; // sum = sum+i;
}

printf("Sum = %d",sum);

return 0;
}
 
Last edited:
Baka eto na sagot TS ^_^

#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>

int
main ()
{
int input;
int sum;
int count;


printf ("Enter an integer: ");
scanf ("%d", &input);
sum = sum + input;

int i = input;
std::stringstream ss;
ss << i;

std::string str;
ss >> str;


for (count = 4; count > 0; --count)
{
printf ("Input another integer: ");
scanf ("%d", &input);
sum = sum + input;

std::stringstream ss;
ss << input;

std::string input;
ss >> input;

str = str + "+" + input;
}

std::cout << "Numbers " + str;
printf (" = %d", sum);
return 0;
}
 
Limang number yung iinput? dapat 5 din yung variables mo for numbers then lima rin yung scanf ex:

int num1, num2, num3, num4, num5, sum = 0;

printf("Input 1st number:");
scanf("%d", &num1);

printf("Input 2nd number:");
scanf("%d", &num2);

printf("Input 3rd number:");
scanf("%d", &num3);

printf("Input 4th number:");
scanf("%d", &num4);

printf("Input5th number:");
scanf("%d", &num5);

kung ganito, di na kailangan ng loop. itotal mo nalang ex:

sum = num1 + num2 + num3 + num4 + num5;

printf("Sum is %d", sum);

or kung required talaga ang looping. try using arrays ex:

int numbers[5];
int sum;

printf("Enter 5 numbers");
for (int i = 0; i < 4; i++) {
scanf("%d", numbers);
}

and para sum, use looping again:

for (int i = 0; i < 4; i++) {
sum = sum + numbers;
}

printf("Sum is %d", sum);


Not sure kung ganyan yung right codes sa C language. You can search about arrays on google.

edit: Yung numbers sa "sum = sum + numbers;" tsaka "scanf("%d", numbers);" lagyan mo ng Open and Close bracket na may letter i sa loob. Di ko alam bakit ayaw lumabas ng brackets pag pinopost ko na e.
 
Last edited:
Status
Not open for further replies.

Similar threads

Back
Top