+ 2

Where's the problem in this code

#include <stdio.h> #include <stdlib.h> int main() { int a,b,i ; //partie1 printf("donner les deux entiers : \n "); scanf("%d %d",&a, &b ); printf("a=%d", a ," et b=%d", b,"\n" ); //partie2 if (a>b) { printf("\n a superieure Ă  b \n " ); } else if (a = b) { printf( " a egale a b \n "); } else { printf("b est superieur Ă  a \n ") ; } //partie3 printf("saisir un entier : ") ; scanf("%d",&a); b=rand() ; if (a>b) { printf("\n a superieure Ă  b" ); } else if (a=b) { printf( "\n a egale a b "); } else { printf("\n b est superieur Ă  a \n ") ; } //partie4 b=rand() ; while ((b<0) || ((b % 100)>=1)) { b=rand() ; } i=0 ; printf("donner un entier : \n"); scanf("%d ,&a") ; while ((i<10)&&(a != b)) { printf("donner un entier : \n"); scanf("%d",&a ); } return 0; }

8th Nov 2020, 2:21 PM
Sabrine Kammoun
Sabrine Kammoun - avatar
3 Answers
+ 3
It helps if you save code and share code link.... Sabrine Kammoun Check this code : share link like this next https://code.sololearn.com/cqX1cwL779Gj/?ref=app //errors removed, read comments for description about edits scanf("%d %d",&a, &b ); //printf("a=%d", a,"et b=%d", b,"\n"); //this is not the correct way //correct way is : printf("a=%d et b=%d\n", a,b); ....... //partie2 else if (a == b){ // using '=' 'is assigning value in (a=b) leads wrong, use == for comparison ....... //partie3 else if(a==b){ //same here use '==' instead of '=' ....... i=0 ; printf("donner un entier : \n"); // scanf("%d ,&a") ; //wrong way of using braces //Correct way is : scanf("%d", &a); while ((i<10)&&(a != b)) { //to stop infinite loop, add i++; i++; printf("donner un entier : \n"); scanf("%d",&a ); } return 0; }
8th Nov 2020, 2:25 PM
Jayakrishna 🇼🇳