1
This is a conditional structure code and repetition For simple in C. However, the output is being the sequence: 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20. The expected output was a sequence of 1 to 10 if the number 1 was read, or a sequence of 1 to 20 if the number 2 was read. Could you please point out the error? Thanks in advance!
#include <stdio.h>
int main()
{
int c1,c2,ops;
printf("Digite um opcao:");
scanf("%d",&ops);
if(ops=1)
{
for(c1=1;c1<=10;c1++)
printf("%d ",c1);
}
if(ops=2)
{
for(c2=1;c2<=20;c2++)
printf("%d ",c2);
}
return 0;
}
Thank you very much!
– Gustavo Medeiros
You’re welcome, we need you ;)
– DbaAlone