81 / 92
Jun 2018
5 months later

Can anyone tell me why am i getting an error for this code(life universe and everything)

#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,n,t=3;
for(i=0;i<t;i++)
{
scanf("%d",&n);
if(n==42)
break;
else
continue;
}
return 0;
}

1 year later

#include<stdio.h>
int main(void) {
int numb;
do{scanf("%d",&numb);
if(numb==42)break;
printf("%d\n",numb);}while( numb>0);

return 0;

}
I WROTE THIS AND THEY TOLD ME I’M WRONG, CORRECT ME PLEASE

Your code is very bad formatted or bad pasted or both.

#include <stdio.h>

int main (void) {
	int numb;
	do {
          scanf ("%d", &numb);
	      if (numb == 42) break;
	      printf ("%d\n", numb);
    } while (numb != 42); // or simple: while (1);

	return 0;
}

PS

Please don’t shout, QUIETER PLEASE!!!

1 month later

My first try on SPOJ.
I can’t use argc+argv on SPOJ, can I?

#include <stdio.h>

int main(int argc, char** argv)
{
    int i = 0;
    for(; i < argc; ++i){
        if(argv[i][0] == '4' && argv[i][1] == '2')
            return 0;
        else
            printf("%s\n",argv[i]);
    }
    return 0;
}

No, You should read from standard input.
Example:
scanf("%i\n", &number);

1 year later

Yes it does give wrong answer because it displays input as well as output
like this :
1
1
4
4
5
5

which is incorrect. Correct me if I am wrong

2 months later

#include
using namespace std;

int main() {

int x;
while(1)
{
	cin>>x;
	cout<<x<<endl;
	if (x==42)
	break;
}
return 0;

}

  • _this code is accepted but what abot number with more than 2 digits .? They will also be taken as input .
2 years later

#include <studio.h>

int main(){
int x;
printf(“Enter the value of x : “);
scanf(”%d”,&x);
for(int i = 1; i < 42; i++){
printf("%d\n",x);
}
return 0;
}

// the solution in c programming language in proper way for the given program line by line…

#include
Using namespace std;

int main(){
int x;
cout << "enter the value of x : " << endl;
cin >> x;

For(int i = 0; i < 42; i++){
Cout << "the value of x is : " << x << endl;
}
return 0;
}

// for c++ this is the solution line by line … It’s looping

You are only reading the value of x once.
You are printing stuff that isn’t asked for. Only print x if it isn’t 42.
You are not checking the value of x to see if it is 42, when you should stop processing.