Skip to main content

Posts

Showing posts from April, 2020

URI Online Judge Solution 1153 Simple Factorial

URI Online Judge Solution 1153 Simple Factorial using C Programming Language. Read a value N. Calculate and write its corresponding factorial.  Factorial of N = N * (N-1) * (N-2) * (N-3) * ... * 1. Input The input contains an integer value N (0 < N < 13). Output The output contains an integer value corresponding to the factorial of N. Input Sample Output Sample 4 24 Solution using C : #include <stdio.h> int main() {     int n,s=1;     scanf("%d",&n);     while(n>0)     {         s *= n;         n--;     }     printf("%d\n",s);     return 0; }

URI Online Judge Solution 1151 Easy Fibonacci

URI Online Judge Solution 1151 Easy Fibonacci using C Programming Language. he following sequence of numbers 0 1 1 2 3 5 8 13 21 ... is known as the Fibonacci Sequence. Thereafter, each number after the first 2 is equal to the sum of the previous two numbers. Write an algorithm that reads an integer N (N < 46) and that print the first N numbers of this sequence. Input The input file contains an integer number N (0 < N < 46). Output The numbers ​​should be printed on the same line, separated by a blank space. There is no space after the last number. Thanks to Cássio F. Input Sample Output Sample 5 0 1 1 2 3 Solution using C : #include <stdio.h> int main() {     int n,i,n1,n2,t;     scanf("%d",&n);     for(i=1; i<=n; i++)     {         if(i==1)         {             n1 = 0;             printf("%d",n1);         }         else if(i==2)         {             n2 = 1;             printf("%d",n2);         }

URI Online Judge Solution 1150 Exceeding Z

URI Online Judge Solution 1150 Exceeding Z using C Programming Language. Write a program that reads two integers: X and Z (Z must be read as many times as necessary, until a number greater than X is read). Count how many integers must be summed in sequence (starting at and including X) so that the sum exceeds Z the minimum possible and writes this number. The input may have, for example, the numbers ​​21 21 15 30. In this case, the number 21 is assumed for X, The numbers 21 and 15 must be ignored because they are smaller or equal to X. The number 30 is within the specification (greater than X) and is valid. So, the final result must be 2 for this test case, because the sum (21 + 22) is bigger than 30. Input The input contains only integer values​​, one per line, which may be positive or negative. The first number is the value of X. The next line will contain Z. If Z does not meet the specification of the problem, it should be read again, as many times as necessary. Outpu

URI Online Judge Solution 1149 Summing Consecutive Integers

URI Online Judge Solution 1149 Summing Consecutive Integers using C Programming Language. Write an algorithm to read a value A and a value N. Print the sum of N numbers from A (inclusive). While N is negative or ZERO, a new N (only N) must be read. All input values are in the same line. Input The input contains only integer values, ​​can be positive or negative. Output The output contains only an integer value. Input Sample Output Sample 3 2 7 3 -1 0 -2 2 7 Solution using C : #include <stdio.h> int main() {     int a,n,s=0;         scanf("%d%d",&a,&n);         while(n<=0)             scanf("%d",&n);         while(n)         {             s += a++;             n--;         }         printf("%d\n",s);     return 0; }

URI Online Judge Solution 1146 Growing Sequences

URI Online Judge Solution 1146 Growing Sequences using C Programming Language. Your program must read an integer  X  indefinited times (the program must stop when  X  is equal to zero). For each  X  print the sequence from 1 to  X , with one space between each one of these numbers. PS: Be carefull. Don't leave any space after the last number of each line, otherwise you'll get  Presentation Error . Input The input file contains many integer numbers. The last one is zero. Output For each number N of the input file, one output line must be printed, from 1 to N like the following example. Be careful with blank spaces after the last line number. Input Sample Output Sample 5 10 3 0 1 2 3 4 5 1 2 3 4 5 6 7 8 9 10 1 2 3 Solution using C : #include <stdio.h> int main() {    int x,i;     while(1)     {         scanf("%d",&x);         if(x==0)             break;         for(i=1; i<=x; i++)         {             printf("%d",i

URI Online Judge Solution 1145 Logical Sequence 2

URI Online Judge Solution 1145 Logical Sequence 2 using C Programming Language. Write an program that reads two numbers X and Y (X < Y). After this, show a sequence of 1 to y, passing to the next line to each X numbers. Input The input contains two integer numbers X (1 < X < 20) and Y (X < Y < 100000). Output Each sequence must be printed in one line, with a blank space between each number, like the following example. Input Sample Output Sample 3 99 1 2 3 4 5 6 7 8 9 10 11 12 ... 97 98 99 Solution using C : #include <stdio.h> int main() {     int x,y,i,j=0;     scanf("%d%d",&x,&y);     for(i=1; i<=y; i++)     {         j++;         printf("%d",i);         if(j==x || i == y)         {             printf("\n");             j=0;         }         else             printf(" ");     }     return 0; }

URI Online Judge Solution 1144 Logical Sequence

URI Online Judge Solution 1144 Logical Sequence using C Programming Language. Write a program that reads an integer N. N * 2 lines must be printed by this program according to the example below. For numbers with more than 6 digits, all digits must be printed (no cientific notation allowed). Input The input file contains an integer  N  (1 <  N  < 1000). Output Print the output according to the given example. Input Sample Output Sample 5 1 1 1 1 2 2 2 4 8 2 5 9 3 9 27 3 10 28 4 16 64 4 17 65 5 25 125 5 26 126 Solution using C : #include <stdio.h> int main() {     int n,i,j;     scanf("%d",&n);     for(i=1; i<=n; i++)     {         for(j=1; j<=2; j++)         {             if(j==1)                 printf("%d %d %d\n",i,i*i, i*i*i);             else                 printf("%d %d %d\n",i,(i*i)+1, (i*i*i)+1);         }     }     return 0; }

URI Online Judge Solution 1143 Squared and Cubic

URI Online Judge Solution 1143 Squared and Cubic using C Programming Language. Write a program that reads an integer N (1 < N < 1000). This N is the number of output lines printed by this program. Input The input file contains an integer N. Output Print the output according to the given example. Input Sample Output Sample 5 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125 Solution using C : #include <stdio.h> int main() {    int n,i;     scanf("%d",&n);     for(i=1; i<=n; i++)     {         printf("%d %d %d\n",i,i*i,i*i*i);     }     return 0; }

URI Online Judge Solution 1142 PUM

URI Online Judge Solution 1142 PUM using C Programming Language. Write a program that reads an integer N. This N is the number of output lines printed by this program. Input The input file contains an integer N. Output Print the output according to the given example. Input Sample Output Sample 7 1 2 3 PUM 5 6 7 PUM 9 10 11 PUM 13 14 15 PUM 17 18 19 PUM 21 22 23 PUM 25 26 27 PUM Solution using C : #include <stdio.h> int main() {     int N,i,j,p=1;     scanf("%d",&N);     for(i=1; i<=N; i++)     {         for(j=1; j<=3; j++)         {             printf("%d ",p++);         }         p++;         printf("PUM\n");     }     return 0; }

URI Online Judge Solution 1134 Type of Fuel

URI Online Judge Solution 1134 Type of Fuel using C Programming. A gas station wants to determine which of their products is the preference of their customers. Write a program to read the type of fuel supplied (coded as follows: 1. Alcohol 2. Gasoline 3. Diesel 4. End). If you enter an invalid code (outside the range of 1 to 4) a new code must be requested. The program will end when the inserted code is the number 4. Input The input contains only integer and positive values. Output It should be written the message: "MUITO OBRIGADO" and the amount of customers who fueled each fuel type, as an example. Input Sample Output Sample 8 1 7 2 2 4 MUITO OBRIGADO Alcool: 1 Gasolina: 2 Diesel: 0 Solution using C : #include <stdio.h> int main() {    int n,a,g,d;     a = g = d = 0;     while(1)     {         scanf("%d",&n);              if(n==4)                 break;         else if(n==1)           a++;         else if(n==2)            

URI Online Judge Solution 1133 Rest of a Division

URI Online Judge Solution 1133 Rest of a Division using C Programming. Write a program that reads two integer numbers X and Y. Print all numbers between X and Y which dividing it by 5 the rest is equal to 2 or equal to 3. Input The input file contains 2 any positive integers, not necessarily in ascending order. Output Print all numbers according to above description, always in ascending order. Input Sample Output Sample 10 18 12 13 17 Solution using C : #include <stdio.h> int main() {     int x,y,i;     scanf("%d%d",&x,&y);     if(x>y)     {         int t = x;             x = y;             y = t;     }     for(i=x+1; i<y; i++)     {         int r = i%5;         if(r == 2 || r == 3)             printf("%d\n",i);     }     return 0; }

URI Online Judge Solution 1132 Multiples of 13

URI Online Judge Solution 1132 Multiples of 13 using C Programming. Write a program that reads two integer numbers X and Y and calculate the sum of all number not divisible by 13 between them, including both. Input The input file contains 2 integer numbers X and Y without any order. Output Print the sum of all numbers between X and Y not divisible by 13, including them if it is the case. Input Sample Output Sample 100 200 13954 Solution using C : #include <stdio.h> int main() {     int x,y,i,s=0;     scanf("%d%d",&x,&y);     if(x<y)     {        for(i=x; i<=y; i++)        {             if(i%13 != 0)                 s += i;        }     }     else     {         for(i=y; i<=x; i++)         {             if(i%13 != 0)                 s += i;         }     }     printf("%d\n",s);     return 0; }

URI Online Judge Solution 1131 Grenais

URI Online Judge Solution 1131 Grenais using C Programming. The  Federação Gaúcha de Futebol  invited you to write a program to present a statistical result of several GRENAIS. Write a program that read the number of goals scored by Inter and the number of goals scored by Gremio in a GRENAL. Write the message "Novo grenal (1-sim 2-nao)" and request a response. If the answer is 1, two new numbers must be read (another input case) asking the number of goals scored by the teams in a new departure, otherwise the program must be finished, printing: - How many GRENAIS were part of the statistics. - The number of victories of Inter. - The number of victories of Gremio. - The number of Draws. - A message indicating the team that won the largest number of GRENAIS (or the message: "Não houve vencedor" if both team won the same quantity of GRENAIS). Input The input contains two integer values​​, corresponding to the goals scored by both teams. Then there is an i

URI Online Judge Solution 1120 Contract Revision

URI Online Judge Solution 1120 Contract Revision using C Programming Language. For years, all contracts of the Association of Contracts for Modernization (ACM) were typed using an old typewriter machine. Recently Mr. Miranda, one of the accountants of the ACM, realized that the machine had a failure in one, and only one, numerical digit. More specifically, the flawed digit, when typed, is not printed on the sheet, as if the corresponding key was not pressed. He realized that this could have changed the numerical representation of contract values. Worried about accounting, Mr. Miranda wants to know, from the original values agreed for the contracts (which he kept in handwritten notes) which values are actually represented in the contracts. For example, if the failed digit in the machine is 5, an agreed value of 1500 would be represented in the corresponding contract as 100, because the digit 5 would not be printed. Note that Mr. Miranda wants to know the numeric value represented

URI Online Judge Solution 1118 Several Scores with Validation

URI Online Judge Solution 1118 Several Scores with Validation using C Programming Language. Write an program to read two scores of a student. Calculate and print the semester average. The program must accept only valid scores (a score must fit in the range [0.10]). Each score must be validated separately. The program must print a message "novo calculo (1-sim 2-nao)" that means "new calculate (1-yes 2-no)". After, the input will be (1 or 2). 1 means a new calculation, 2 means that the execution must be finished. Input The input file contains several positive or negative floating-point (double) values​. After the input of 2 valid scores, an integer number  X  will be read. Your program must stop when  X  = 2. Output If an invalid score is read, must be printed the message "nota invalida". When two valid scores are read, the message "media = " must be printed folowed by the average between these 2 scores. The message "novo c