Codeforces 977A Wrong Subtraction solution in CPP

Codeforces 977A Wrong Subtraction solution in CPP

Question link: Codeforces 977A Wrong Subtraction solution in CPP Wrong Subtraction #include<bits/stdc++.h> using namespace std; int main() { int n,k,r=0; cin>>n>>k; for(int i=1;i<=k;i++) { r=n%10; if(r==0) { n/=10; } else { n=n-1; } } cout<<n; } Code Explanation This is a C++ code that takes two integers n and k as input from the user, … Read more

Sum of an array in c || Sum of array Elements in C

sum of an array in c

Sum of an array in c Example 1 #include <stdio.h> int main() { int arr[5] = {1, 2, 3, 4, 5}; // Declare and initialize an array of 5 integers int sum = 0; int i; // Calculate the sum of the elements in the array for (i = 0; i < 5; i++) { … Read more

Codeforces 59AWord Solution in C/CPP

Codeforces 59AWord Solution

Codeforces 59AWord Solution question Codeforces 59AWord Solution in CPP #include<iostream> #include<string> #include<algorithm> using namespace std; int main() { string a; int l=0,u=0; cin>>a; for(int i=0;i<a.size();i++) { if(a[i]>=’a’&& a[i]<=’z’) { l++; } else u++; } if(l>=u){ for(int i=0;i<a.size();i++)//Codeforces 59A.Word Solution a[i]=tolower(a[i]); cout<<a<<endl; } else { for(int i=0;i<a.size();i++) { a[i]=toupper(a[i]); } cout<<a<<endl; } } Codeforces 59AWord Solution … Read more

Elephant Codeforces || Codeforces 617A Elephant solution in C++

Elephant Codeforces

Codeforces Elephant Question Elephant Codeforces solution in C++ An elephant decided to visit his friend. It turned out that the elephant’s house is located at point 0 and his friend’s house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to … Read more

Codeforces 546A Soldier and Bananas solution in C++

Codeforces 546A Soldier and Bananas solution in C++

Codeforces 546A. Soldier and Bananas Question A. Soldier and Bananas A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana). He has n dollars. How many dollars does he have to borrow from his … Read more

Array Addition using 2d array in C || Add Two Matrices Using Multi-dimensional Arrays in C

2d array in C

Array Addition using 2d array in C #include<stdio.h> void main() { int i,j; int a[3][4],b[3][4],c[3][4]; for(i=0;i<3;i++){ for(j=0;j<4;j++){ printf(“a[%d][%d]”,i,j); scanf(“%d”,&a[i][j]); } } for(i=0;i<3;i++){ for(j=0;j<4;j++){ printf(“%d “,a[i][j]); } printf(“\n”); } for(i=0;i<3;i++){ for(j=0;j<4;j++){ printf(“b[%d][%d]”,i,j); scanf(“%d”,&b[i][j]); } } for(i=0;i<3;i++){ for(j=0;j<4;j++){ printf(“%d “,b[i][j]); } printf(“\n”); } printf(“\n”); printf(“sum of two array is :\n”); for(i=0;i<3;i++){ for(j=0;j<4;j++){ c[i][j]=a[i][j]+b[i][j]; } } for(i=0;i<3;i++){ for(j=0;j<4;j++){ … Read more

2D Arrays in C || C Multidimensional Arrays

2D Arrays in C

Understanding 2D Arrays in C Multidimensional arrays in C are those that have more than one dimension. They can be compared to a table with columns and rows. In C, a multidimensional array can be declared using the following syntax: data_type array_name[row_size][column_size]; For instance, we may write the following to declare a 2D array with … Read more

How to start programming?

How to start programming?

How to start programming? Starting to learn to program can seem daunting, but with the right approach, it can be a fun and rewarding experience. Here are some steps to help you get started: Remember that programming is a skill that takes time and practice to develop. Stay motivated, be persistent, and enjoy the learning … Read more

Stones On The Table Codeforces Solution || Codeforces 266A

Stones On The Table Codeforces Solution

Question Stones on the Table Codeforces Solution in C++ Problem:There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring … Read more