Review c + +

Computer science2.96 KB

/ * Multiplication table * / # include void main () (int n, cont, prod; do (printf ( "Enter a positive integer:") scanf ( "% i", & n);) while (n < 0); cont = 1 while (cont <= 10) (prod = n * cont; printf ( "\ n% i *% i =% i", n, cont, prod); cont + + / * cont = cont +1 * /))

/ * Multiple of 3 * / # include void main () (int A, B; printf ( "enter any number:") scanf ( "% d", & A), B = A, while (A> = 3) (A = A-3;) if (A == 0) (printf ( "% d is a multiple of 3", B);) else (printf ( "% d is not a multiple of 3", B);))

/ * Sum the first hundred numbers from N * / # include void main () (int N, cont, sum; do (printf ( "Enter a positive number") scanf ( "% i", & N);) while (N <0); cont = N; sum = N while (cont <100) (sum = sum + (cont +1); cont + +;) printf ( "The sum of the first hundred numbers is:% i", sum );)

/ * 20Numeros * / # include void main () (int a, maximum, minimum, counter, accumulator; float average; printf ( "Enter an integer:") scanf ( "% i", & a); accumulator = 0 , max = a; minimum = a; counter = 19; while (count> 0) (printf ( "Enter an integer:") scanf ( "% i", & a) if (a> maximum) (maximum = a;) else if (a <minimum) (minimum = a;) count -; accumulator = accumulator + a;) mean = acumulador/20 printf ( "\ n The highest is:% i the lowest is:% i mean is% f ", maximum, minimum, average);)

/ * The 2 children * / # include void main () (int min1, min2, Contin, A, N; do (printf ( "how many numbers you will enter:") scanf ( "% d", & N);) while (N <2) printf ( "enter the first number:") scanf ( "% d", & A) min1 = A; printf ( "Enter the second number:") scanf ( "% d", & A) if (min1> A) (min2 = min1; min1 = A;) else (min2 = A;) cont = N-2 while (cont> 0) (printf ( "Enter another number:"); scanf ( "% d", & A), if (A


/ * Major * / # include void main () (int a, cont, max; printf ( "enter an integer:") scanf ( "% d", & a); max = a; cont = 19; while (cont> 0) (printf ( "enter an integer:") scanf ( "% d", & a); if (max <a) max = a; cont -;) printf ( "\ nThe most is: % d ", max);)

/ * Factorial * / # include void main () (float num1, fact; do (printf ( "enter an integer:") scanf ( "% f", & num1);) while (num1 <0) if (num1 == 0) Fact = 1; else fact = 1 while (nume1> 0) (fact = fact * num1, num1 -;) printf ( "\ n fact is:% d", fact))

/ * major, minor * / # include void main () (int a, b, c, max, min; printf ( "enter an integer:") scanf ( "% i", & a); printf ( "enter a 2nd number: ") scanf ("% i ", & b) if (a> b) (max = a; min = b;) else (max = b; min = a;) printf (" enter a 3 rd number: ") scanf ("% i ", & c) if (x> max) (max = c;) else (if (min> c) (min = c;)) printf (" \ nThe larger; % i ", max) printf (" \ nThe lower,% i ", min);)

Download

PDF Word HTML