Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.
/**Bismillahir Rahmanir Rahim.**/ #include <stdio.h> int main() { int a,b,c,d=0; while(1) { scanf("%d%d", &a, &b); if(a<=0 || b<=0) break; else { d=0; if(a<b) { for(c=a; c<=b; c++) { printf("%d ",c); d+=c; } printf("Sum=%d\n",d); } else if(a>b) { for(c=b; c<=a; c++) { printf("%d ",c); d+=c; } printf("Sum=%d\n",d); } } } return 0; }
why give,,,while(1)
ReplyDelete1 means true.
DeleteFor that, this while loop will always continue if I don't break it.
This comment has been removed by the author.
Delete//I THINK MY CODE IS LITTLE BIT MAKES SENSE
Delete#include
using namespace std;
int main()
{
int n , m , sum=0;
while (cin >> m >> n)
{
sum=0;
if (m<=0||n<=0){return 0;}
else
{
if (m > n)
{
for (int i = n ; i <= m ; ++i)
{
cout << i << " ";
sum+=i;
}
}
else if(n>m)
{
for (int i = m ; i <= n ; ++i)
{
cout << i << " ";
sum+=i;
}
}
}
cout << "Sum=" << sum <<endl;
}
}
This comment has been removed by the author.
ReplyDeleteWhy this code shows presentation error
ReplyDelete#include
int main()
{
int M,N,i,a,sum;
while(1)
{
scanf("%d%d",&M,&N);
if(M<=0||N<=0)
break;
if(N>M)
{
a=M;
M=N;
N=a;
}
sum=0;
for(i=N;i<=M;i++)
{
sum+=i;
printf("%d ",i);
}
printf("sum=%d\n",sum);
}
return 0;
}
your print "sum" has a tiny "s", try to replace it to a big "s". like> Sum.
Delete
ReplyDelete#include
using namespace std;
int main()
{
int a,b,sum=0;
cin>>a>>b;
if (a<=0 ||b<=0)
{
break ;
}
else if (a>b)
{
swap(a,b);
}
for (int i=a;i<=b;i++)
{
printf("%d ",i);
sum=sum+i;
}
cout<<endl;
printf("sum=%d\n",sum);
}
#include
ReplyDeleteint main()
{
int x,y,i,count =0;
while(1)
{
scanf("%d%d",&x,&y);
if(x<=0 || y<=0)
{
break;
}
else
{
if(x>y)
{
for(i=y;i<=x;i++)
{
printf("%d ",i);
count=count+i;
}
printf("Sum=%d\n",count);
}
else if(x<y)
{
for(i=x;i<=y;i++)
{
printf("%d ",i);
count=count+i;
}
printf("Sum=%d\n",count);
}
}
}
return 0;
}
why does it shows 70% wrong?
This comment has been removed by the author.
ReplyDelete#include
ReplyDelete#include
int main(){
int M, N,cont,
soma = 0;
while (1){
scanf("%d %d", &M, &N);
if (M==0 || N==0)
break;
else if(M>N){
for(cont=N; cont<=M; cont++){
soma=soma+cont;
printf("%d ", cont);
}
printf("Sum=%d\n" ,soma);
}else if (M<N){
for(cont=M; cont<=N; cont++){
soma=soma+cont;
printf("%d " ,cont);
}
printf("Sum=%d\n" ,soma);
}
soma=0;
}
return 0;
}
This shows 10% WRONG, WHY ??????
The first if is missing M<=0 AND N<=0
DeleteWhy this is wrong (55% error)
ReplyDelete#include
#include
int main () {
int x,y,a,b, soma=0, fim;
do{
scanf("%d%d", &x, &y);
a=x;
b=y;
if(x>y){
a=y;
b=x;
}
if(a!=0 && b!=0 && a>0 && b>0){
do{
printf("%d ", a);
soma+=a;
a++;
}while(a<b+1);
printf("Sum=%d\n", soma);
soma=0;
}
else
fim=0;
}while(fim!=0);
system("pause");
}
ReplyDeletepackage URI_Problem;
import java.util.Scanner;
public class prob_1101 {
public static void main(String[] args) {
int x,y, temp, sum=0, i;
Scanner in = new Scanner(System.in);
while(true){
x = in.nextInt();
y = in.nextInt();
if(x==0 || y==0){
break;
}
else if(x>y){
{
temp = x;
x = y;
y = temp;
for (i = x; i <= y; i++) {
System.out.print(i+" ");
sum+=i;
}
System.out.println(" Sum="+sum);
}
}
}
}
}