Knowee
Questions
Features
Study Tools

Les deux programmes suivants sont-ils semblables ? Justifier votre réponse.n = int(input("Entrez n : ")) n = int(input("Entrez n : "))if n%2 == 1 : if n%2 == 1 :n = 3*n+1 n = 3*n+1else : if n%2 == 0 :n = n//2 n = n//2print(n) print(n)

Question

Les deux programmes suivants sont-ils semblables ? Justifier votre réponse.n = int(input("Entrez n : ")) n = int(input("Entrez n : "))if n%2 == 1 : if n%2 == 1 :n = 3n+1 n = 3n+1else : if n%2 == 0 :n = n//2 n = n//2print(n) print(n)

🧐 Not the exact question you are looking for?Go ask a question

Solution

Oui, les deux programmes sont semblables. Ils effectuent tous les deux la même opération sur la variable 'n' en fonction de si 'n' est pair ou impair. Si 'n' est impair, ils multiplient 'n' par 3 et ajoutent 1. Si 'n' est pair, ils divisent 'n' par 2. Enfin, ils impriment la valeur de 'n'. La seule différence est la façon dont ils vérifient si 'n' est pair ou impair. Le premier programme utilise une déclaration 'else' pour signifier que 'n' est pair si 'n' n'est pas impair. Le deuxième programme vérifie explicitement si 'n' est pair avec 'if n%2 == 0'. Cependant, cette différence est mineure et ne change pas le fonctionnement du programme. Donc, on peut dire que les deux programmes sont effectivement semblables.

This problem has been solved

Similar Questions

What sequence of numbers would be printed if the following function were executed with the value of N being 2?

n_livres = int(input("Entrez le nombre de livres empruntés : "))if n_livres == 2:        montant= 5elif n_livres > 2:        livres_supplementaires = n_livres - 2        montant = 5+ (2 * livres_supplementaires)else:       print("Entrée non valide. Veuillez saisir un nombre correcte !")       montant= 0if montant != 0:       print("Montant :", montant, "Dt")a.Montant : 11 Dtb.Montant : 30 Dtc.Entrée non valide. Veuillez saisir un nombre correcte !d.Montant : 13 Dte.Entrée non valide. Veuillez saisir un nombre correcte !Montant : 0 Dt

#include <iostream>using namespace std;int main(){ int n; cin >> n; if(n % 2 == 0) cout << n << endl; else cout << n * 2 << endl; return 0;}

Single File Programming QuestionProblem StatementGiven a non-negative integer N, the task is to check if N is a power of 2. Print 'YES' if N is the power of 2; else, print 'NO'.Example 1Input: N = 8Output: YESExplanation: 8 is equal to 2 raised to 3 (23 = 8).Example 2Input: N = 98Output: NOExplanation: 98 cannot be obtained by any power of 2.Note: This question was asked in Adobe coding test.Input format :The input consists of an integer N, representing the non-negative integer.Output format :If N is a power of 2, the output is "YES".If N is not a power of 2, the output is "NO".Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ N ≤ 512Sample test cases :Input 1 :20Output 1 :NOInput 2 :64Output 2 :YESInput 3 :98Output 3 :NONote :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.Marks :

Single File Programming QuestionProblem StatementGiven a non-negative integer N, the task is to check if N is a power of 2. Print 'YES' if N is the power of 2; else, print 'NO'.Example 1Input: N = 8Output: YESExplanation: 8 is equal to 2 raised to 3 (23 = 8).Example 2Input: N = 98Output: NOExplanation: 98 cannot be obtained by any power of 2.Note: This question was asked in Adobe coding test.Input format :The input consists of an integer N, representing the non-negative integer.Output format :If N is a power of 2, the output is "YES".If N is not a power of 2, the output is "NO".Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ N ≤ 512Sample test cases :Input 1 :20Output 1 :NOInput 2 :64Output 2 :YESInput 3 :98Output 3 :NONote :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.