Advertisement
Guest User

C TP2

a guest
Oct 4th, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.87 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. exo8();
  6. }
  7.  
  8. int exo1()
  9. {
  10. int multi, i, nb;
  11. printf("entrez un nombre entier positif\n");
  12. scanf("%i", &nb);
  13.  
  14. //exo 7
  15. if (i < 0)
  16. {
  17. printf("respectes les consignes !");
  18. exit(1);
  19. }
  20.  
  21. i = 1;
  22. while (i<=10)
  23. {
  24. multi = i * nb;
  25. printf("%i * %i = %i\n", i, nb, multi);
  26. i++;
  27. }
  28. }
  29.  
  30. int exo2()
  31. {
  32. //factorielle de i
  33. printf("entrez i un entier naturel\n");
  34. int i, facto, cpt;
  35. cpt = 0;
  36. facto = 1;
  37. scanf("%i",&i);
  38.  
  39. if (i < 0)
  40. {
  41. printf("respectes les consignes !");
  42. exit(1);
  43. }
  44.  
  45. while (cpt < i)
  46. {
  47. cpt++;
  48. facto = facto * cpt;
  49. }
  50. printf("%i", facto);
  51.  
  52. }
  53.  
  54. int exo3()
  55. {
  56. printf("afficher les 10 premiers termes d'une suite : \n");
  57. int n ,u, v, sommeU = 0, sommeV = 0;
  58. n = 0;
  59. while (n<=10)
  60. {
  61. u = 3*n+5;
  62. v = (3*n*n+5)/(n*n+1);
  63. printf("U%i = %i\n", n, u);
  64. printf("V%i = %i\n", n, v);
  65. sommeU = sommeU + u;
  66. sommeV = sommeV + v;
  67. printf("sommeU = %i\n", sommeU);
  68. printf("sommeV = %i\n", sommeV);
  69. n++;
  70. }
  71.  
  72. }
  73.  
  74. int exo4()
  75. {
  76. int a, b;
  77. printf("Entrez une annee comprise entre 1512 et 3999: \n");
  78. scanf("%i", &a);
  79. if ((a < 1512) || (a > 3999))
  80. {
  81. printf("Respectes les consignes");
  82. exit(1);
  83. }
  84. else
  85. {
  86.  
  87. if (a%400==0)
  88. {
  89. b = 1 ;
  90. }
  91. else
  92. {
  93. if ((a%4==0) && (a%100!=0))
  94. {
  95. b = 1;
  96. }
  97. else
  98. {
  99. b = 0;
  100. }
  101. }
  102.  
  103. if (b == 1)
  104. {
  105. printf("L'annee est bissextile !");
  106.  
  107. }
  108. else
  109. {
  110. printf("L'annee n'est pas bissextile !");
  111. }
  112. }
  113. }
  114.  
  115. int exo5()
  116. {
  117. float a,b,c,moy;
  118. printf("entrez les 3 notes :\n");
  119. scanf("%f",&a);
  120. scanf("%f",&b);
  121. scanf("%f",&c);
  122.  
  123. if ( (a<0) || (b<0) || (c<0))
  124. {
  125. printf("respectes les consignes !");
  126. exit(1);
  127. }
  128.  
  129. if (b < a)
  130. {
  131. if (b < c)
  132. {
  133. moy = (a + c)/2;
  134. }
  135. }
  136. if (a < b)
  137. {
  138. if (a < c)
  139.  
  140. {
  141. moy = (b + c)/2;
  142. }
  143. }
  144. if (c < a)
  145. {
  146. if (c < b)
  147.  
  148. {
  149. moy = (a + b)/2;
  150. }
  151. }
  152. printf("%f",moy);
  153. return(moy);
  154. }
  155.  
  156. int exo6()
  157. {
  158. printf("Saisir l'heure sous la forme HHMMSS:\n ");
  159. int h, hh, m, mm, s, heure, min, sec;
  160. scanf("%i",&h);
  161.  
  162. if (h%100 == 59)
  163. {
  164. hh=h+41;
  165.  
  166. m = hh%10000;
  167. mm = m/100;
  168.  
  169. if (mm == 60)
  170. {
  171. hh=hh+4000;
  172. mm = 0;
  173.  
  174. s = hh/10000;
  175. if (s == 24)
  176. {
  177. hh = hh + 760000;
  178. hh = (hh%100);
  179. printf("%i\n",hh);
  180. }
  181. else
  182. {printf("%i\n",hh);}
  183. }
  184. else
  185. {printf("%i\n",hh);}
  186. }
  187.  
  188. else
  189. {
  190. hh = h + 1;
  191. printf("%i\n",hh);
  192. }
  193.  
  194. heure = hh/10000;
  195. min = (hh/100)%100;
  196. sec = hh%100;
  197. printf("Il est %iH%iM%iS", heure,min,sec);
  198. }
  199.  
  200. int exo8() // ne marche pas quand on tente d'en sortir
  201. {
  202. int nb = 0, go = 1;
  203. while (go == 1)
  204. {
  205. printf("entrez un chiffre (entre 0 et 9 bande d'incultes) ou # pour quitter\n");
  206. scanf("%i",&nb);
  207. if (nb == "#")
  208. {
  209. go = 0;
  210. exit(1);
  211.  
  212. }
  213. else if ((nb < 0 || nb > 9))
  214. {
  215. printf("respectes les consignes !\n");
  216. }
  217. else if (nb == 0)
  218. {
  219. printf("zero\n");
  220. }
  221. else if (nb == 1)
  222. {
  223. printf("un\n");
  224. }
  225. else if (nb == 2)
  226. {
  227. printf("deux\n");
  228. }
  229. else if (nb == 3)
  230. {
  231. printf("trois\n");
  232. }
  233. else if (nb == 4)
  234. {
  235. printf("quatre\n");
  236. }
  237. else if (nb == 5)
  238. {
  239. printf("cinq\n");
  240. }
  241. else if (nb == 6)
  242. {
  243. printf("six\n");
  244. }
  245. else if (nb == 7)
  246. {
  247. printf("sept\n");
  248. }
  249. else if (nb == 8)
  250. {
  251. printf("huit\n");
  252. }
  253. else if (nb == 9)
  254. {
  255. printf("neuf\n");
  256. }
  257. }
  258. exit(1);
  259. }
  260.  
  261. int exo9_1()
  262. {
  263. int multi, i, nb;
  264. i = 1, nb = 1;
  265. while (nb > 0)
  266. {
  267. printf("entrez un nombre entier positif\n");
  268. scanf("%i", &nb);
  269. i = 1;
  270. while (i<=10)
  271. {
  272. multi = i * nb;
  273. printf("%i * %i = %i\n", i, nb, multi);
  274. i++;
  275. }
  276. }
  277. }
  278.  
  279. int exo9_4()
  280. {
  281. int a, b;
  282. a = 2000;
  283. while ((a > 1512) && (a < 3999))
  284. {
  285. printf("Entrez une annee comprise entre 1512 et 3999: \n");
  286. scanf("%i", &a);
  287. if (a%400==0)
  288. {
  289. b = 1 ;
  290. }
  291. else
  292. {
  293. if ((a%4==0) && (a%100!=0))
  294. {
  295. b = 1;
  296. }
  297. else
  298. {
  299. b = 0;
  300. }
  301. }
  302.  
  303. if (b == 1)
  304. {
  305. printf("L'annee est bissextile !");
  306.  
  307. }
  308. else
  309. {
  310. printf("L'annee n'est pas bissextile !");
  311. }
  312. }
  313. exit(1);
  314. }
  315.  
  316. int exo10()
  317. {
  318.  
  319. printf("exo 7 : Afficher une date du 21eme siecle sous la forme JJ mois 20YY");
  320. printf("Entrer une date sous la forme JJMMYY\n");
  321. long date;
  322. int jour, mois, annee;
  323. scanf("%i", &date);
  324. jour = date/10000;
  325. mois = (date - jour*10000)/100;
  326. annee = date%100;
  327. printf("la date donnee est le %i ", jour);
  328. if (mois == 1)
  329. {
  330. printf("janvier");
  331. }
  332. if (mois == 2)
  333. {
  334. printf("fevrier");
  335. }
  336. if (mois == 3)
  337. {
  338. printf("mars");
  339. }
  340. if (mois == 4)
  341. {
  342. printf("avril");
  343. }
  344. if (mois == 5)
  345. {
  346. printf("mai");
  347. }
  348. if (mois == 6)
  349. {
  350. printf("juin");
  351. }
  352. if (mois == 7)
  353. {
  354. printf("juillet");
  355. }
  356. if (mois == 8)
  357. {
  358. printf("aout");
  359. }
  360. if (mois == 9)
  361. {
  362. printf("septembre");
  363. }
  364. if (mois == 10)
  365. {
  366. printf("octobre");
  367. }
  368. if (mois == 11)
  369. {
  370. printf("novembre");
  371. }
  372. if (mois == 12)
  373. {
  374. printf("decembre");
  375. }
  376.  
  377. printf("20%i",annee);
  378.  
  379. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement