Saturday, April 16, 2016

URI Solution 1073 in C, C++ and Java language


URI Online Judge | 1073

Even Square

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Read an integer N. Print the square of each one of the even values from 1 to including if it is the case.

Input

The input contains an integer (5 < < 2000).

Output

Print the square of each one of the even values from 1 to N, as the given example.
Be carefull! Some language automaticly print 1e+006 instead 1000000. Please configure your program to print the correct format setting the output precision.
Input SampleOutput Sample
62^2 = 4
4^2 = 16
6^2 = 36
 


Solution 1073 in Java language:

  1. import java.util.Scanner;
  2. public class URI_1072 {
  3. public static void main(String[] args) {
  4. int N , X, in = 0, out = 0;
  5. int interval_start =10,interval_end =20 ;
  6. Scanner input =new Scanner(System.in);
  7. N =input.nextInt();
  8. for (int i = 1; i <= N; i++) {
  9. X =input.nextInt();
  10. if (X >= interval_start && X <= interval_end) {
  11. in += 1;
  12. }else {
  13. out += 1;
  14. }
  15. }
  16. System.out.print(in+" in\n"+out +" out\n");
  17. }
  18. }

URI Solution 1073 in C

  1. #include <stdio.h>
  2. int main()
  3. {
  4. int n, i;

  5. scanf("%d", &n);

  6. for ( i = 1; i <= n; ++i)
  7. {
  8. if(i % 2 == 0){
  9. printf("%d^2 = %d\n", i,(i * i));
  10. }
  11. }

  12. return 0;
  13. }

URI Solution 1073 in C++


  1. #include <iostream>

  2. using namespace std;

  3. int main()
  4. {
  5. int n;

  6. cin >> n;

  7. for (int i = 1; i <= n; ++i)
  8. {
  9. if(i % 2 == 0){
  10. cout << i << "^2 = " << (i * i) << endl;
  11. }
  12. }

  13. return 0;
  14. }





No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.