Posts

ACCU WEATHER

Swap the integers

Given two Integer numbers A and B. Swap the values of A nad B. *Hint: Try to solve them using different logics. There is 8 Possible ways to implement this 1. Using 3rd variable Using Additon Operator Using Multiplicaton Operator Without using 3rd variable Using XOR operator Using single statement and Many more ..... Input Format First line contains No of test cases T Next followed T lines each line contains two space seperated values. Constraints 1<= T <= 100 1<= A, B <= 9000 Output Format Print the values of A & B after applying swapping. Sample Input 0 5 1 2 3 5 10 34 23 43 100 1 Sample Output 0 2 1 5 3 34 10 43 23 1 100 Sample Input 1 1 99 1987 Sample Output 1 1987 99 Source Code: import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner ik=new Scanner(System.in); ...

Sum of alternative Numbers

Given a values N. Find the sum's of alternative the numbers from 0 to N. Input Format Single value represents N Constraints 0<= N <= 10,00,000 Output Format Two spaceseperated value represents sum's of alternative values from 0 to N. Sample Input 0 5 Sample Output 0 6 9 Explanation 0 Given N value 5. The numbers from 0 to 5 is 0,1,2,3,4,5 Alternative Sum1=0+2+4=6 alternative sum2= 1+3+5=9 Sample Input 1 1 Sample Output 1 0 1 Source Code: #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { long long int n,c=0,c1=0,j=1,i=0; scanf("%lld",&n); while(i<=n) { c=c+i; i=i+2; } while(j<=n) { c1=c1+j; j=j+2; } printf("%lld %lld",c,c1); return 0; }

Sum of numbers

Given a values N. Find the sum of all the numbers from 0 to N. Input Format Single value represents N. Constraints 0<= N <= 10,00,000 Output Format Single value represents sum of all the values from 0 to N. Sample Input 0 10 Sample Output 0 55 Sample Input 1 16 Sample Output 1 136 Source Code: #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { long long int n,c=0,i; scanf("%lld",&n); for(i=0;i<=n;i++){ c=c+i; } printf("%lld",c); return 0; }

IsEven

Given an integer N. Find whether the N is even or not. *Hint: Try to solve this using all of the following logics. Using Modulor Operator Using shift Operator Using Division, Multiplication operator Using AND Operator. Input Format Single line of integer represents T, No of test cases followed by T space seperated integer values. Constraints 1<= T <= 100 0<= N <= 1000000000000 Output Format Print Yes if it is even number Print No if it is Odd Number Sample Input 0 5 2 4 3 5 123 Sample Output 0 Yes Yes No No No Sample Input 1 3 10004 23453 12345 Sample Output 1 Yes No No Source Code: import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner ik=new Scanner(System.in); int n=ik.nextInt(); for(int i=0;i<n;i++) { int a=ik.nextInt(); i...