Skip to main content

Posts

Showing posts from December, 2022

Sum of Digits || FLOW006 || Programming using C++

Problem You're given an integer  N . Write a program to calculate the sum of all the digits of  N . Input Format The first line contains an integer  T , the total number of testcases. Then follow  T  lines, each line contains an integer  N . Output Format For each test case, calculate the sum of digits of  N , and display it in a new line. Constraints 1 \leq T \leq 1000 1 ≤ T ≤ 1000 1 \leq N \leq 1000000 1 ≤ N ≤ 1000000 Sample 1: Input Output 3 12345 31203 2123 15 9 8   ANSWER:- #include<iostream> using namespace std; int main(){     int test;     cin>>test;     while(test -- ){         int n,rem, sum = 0;         cin>>n;         while(n>0){         rem = n % 10;         sum += rem;         n /= 10;         }         cout<<sum<<endl;     }     return 0; }

Find Remainder || Codechef || FLOW002 || Programming using C++

Problem Write a program to find the remainder when an integer  A  is divided by an integer  B . Input The first line contains an integer  T , the total number of test cases. Then  T  lines follow, each line contains two Integers  A  and  B . Output For each test case, find the remainder when  A  is divided by  B , and display it in a new line. Constraints 1  ≤   T   ≤  1000 1  ≤   A,B   ≤  10000 Sample 1: Input Output 3 1 2 100 200 40 15 1 100 10 ANSWER:-  #include <iostream> using namespace std; int main(){     int a,b;     int t;     cin>>t;     for(int i=0 ; i<t ; i++){     cin>>a>>b;     int c = a%b;     cout<<c<<endl;     }     return 0; }

Enormous Input Test || Codechef || INTEST || Programming using C++

Problem You are given  N N  integers. Find the count of numbers divisible by  K K . Input Format The input begins with two positive integers  N N ,  K K . The next  N N  lines contains one positive integer each denoted by  A_i A i ​ . Output Format Output a single number denoting how many integers are divisible by  K K . Constraints 1 \leq N, K \leq 10^7 1 ≤ N , K ≤ 1 0 7 1 \leq A_i \leq 10^9 1 ≤ A i ​ ≤ 1 0 9 Sample 1: Input Output 7 3 1 51 966369 7 9 999996 11 4 Explanation: The integers divisible by  3 3  are  51, 966369, 9, 51 , 966369 , 9 ,  and  999996 999996 . Thus, there are  4 4   integers in total.   ANSWER:- #include <iostream> using namespace std; int main() {     int n , k , count=0;     cin>>n>>k;     int a[n];     for(int i = 0 ; i<n ; i++)     {         cin>>a[i];     }     for(int j=0 ; j<n ; j++)     {         if(a[j] % k == 0 )         {             count++;         }     }     cout<<count;     return 0; }

Number Mirror Problem || Codechef || START01

Problem Write a program that takes a number  N  as the input, and prints it to the output. Input Format The only line contains a single integer. Output Format Output the answer in a single line. Constraints 0 \leq N \leq 10^5 0 ≤ N ≤ 1 0 5 Sample 1: Input Output 123 123 Sample 2: Input Output 15 15 ANSWER: #include <iostream> using namespace std; int main(){ int a;  cin>>a; cout<<a; return 0; }