jeudi 5 avril 2018

C programming while loop

I was trying to show alternating series using if statement nested in a while loop. That's the code.

main(){
printf("Enter a number: ");
int n1;
scanf(" %d",n1);
int temp =1;

while(temp<=n1)
{
if(temp%2 ==0){
    printf(" %d",-1*temp);
    temp++;
}else{
    printf(" %d", temp);
    temp++;
   }
 }


}

The compiler does not show any error, but while the program is running it says that it stopped working. Any sugestions?

Aucun commentaire:

Enregistrer un commentaire