In this blog I am providing you major concepts of of Java, C++, C & Algorithms etc.
Wednesday, 25 June 2025
C Programming Solved Problems Let us C Yashwant Kanitkar Chapter 2
C Programming Solved Problems Let us C Yashwant Kanitkar Chapter 1
Q:(f) Paper of size A0 has dimensions 1189 mm x 841 mm. Each subsequent size A(n) is defined as A(n-1) cut in half parallel to its shorter sides. Thus paper of size A1 would have dimensions 841 mm x 594 mm. Write a program to calculate and print paper sizes A0, A1, A2, … A8.
#include <stdio.h>
int main()
{
double a[9][2]={{1189,841}};
int i,j;
for(i=1;i<=8;i++)
{
for(j=0;j<=0;j++)
{
if(a[i-1][j]>a[i-1][j+1])
{
a[i][j+1]=a[i-1][j]/2;
a[i][j]=a[i-1][j+1];
}
else
{
a[i][j+1]=a[i-1][j+1]/2;
a[i][j]=a[i-1][j];
}
}
}
for(i=0;i<=8;i++)
{
for(j=0;j<=1;j++)
{
printf("%lf\t",a[i][j]);
}
printf("\n");
}
return 0;
}
Tuesday, 24 June 2025
C Programming Solved Problems Let us C Yashwant Kanitkar Chapter 1
Q: (e) The length and breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area and perimeter of the rectangle, and the area and circumference of the circle.
#include <stdio.h>
int main()
{
double l,b,arearec,perirec,r,areacir,circumcir;
printf("Enter Length & Breadth of Rectangle\n");
scanf("%lf%lf",&l,&b);
printf("Enter Radius of Circle\n");
scanf("%lf",&r);
arearec=l*b;
perirec=2*(l+b);
areacir=3.14*r*r;
circumcir=2*3.14*r;
printf("Area of Rectangle is %lf\n",arearec);
printf("Perimeter of Rectangle is %lf\n",perirec);
printf("Area of Circle is %lf\n",areacir);
printf("Circumference of Circle is %lf\n",circumcir);
return 0;
}
Download Source Code
C Programming Solved Problems Let us C Yashwant Kanitkar Chapter 1
Q: (d) Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to convert this temperature into Centigrade degrees.
#include <stdio.h>
int main()
{
double f, c;
printf("Enter temperature in Fahrenheit: ");
scanf("%lf", &f);
c=(f - 32) * 5.0 / 9.0;
printf("%lf Fahrenheit is equal to %lf Celsius\n", f, c);
return 0;
}
Tuesday, 17 June 2025
C Programming Solved Problems Let us C Yashwant Kanitkar Chapter 1
Q: (c) If the marks obtained by a student in five different subjects are input through the keyboard, write a program to find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.
/*Q: (c) If the marks obtained by a student in five different subjects are input through the keyboard,
write a program to find out the aggregate marks and percentage marks obtained by the student.
Assume that the maximum marks that can be obtained by a student in each subject is 100.*/
#include<stdio.h>
#include<conio.h>
void main()
{
double m1,m2,m3,m4,m5,tot,per;
clrscr();
printf("Enter Marks in 5 Subjects out of 100 each\n");
printf("Enter Marks in Subject 1\n");
scanf("%lf",&m1);
printf("Enter Marks in Subject 2\n");
scanf("%lf",&m2);
printf("Enter Marks in Subject 3\n");
scanf("%lf",&m3);
printf("Enter Marks in Subject 4\n");
scanf("%lf",&m4);
printf("Enter Marks in Subject 5\n");
scanf("%lf",&m5);
tot=m1+m2+m3+m4+m5;
per=tot/5;
printf("Total Marks = %lf\n",tot);
printf("Percentage = %lf",per);
getch();
}
C Programming Solved Problems Let us C Yashwant Kanitkar Chapter 1
Q: (b) The distance between two cities (in km.) is input through the keyboard. Write a program to convert and print this distance in meters, feet, inches and centimeters.
/*Q: (b) The distance between two cities (in km.) is input through the keyboard.
Write a program to convert and print this distance in meters, feet, inches and centimeters.*/
#include<stdio.h>
#include<conio.h>
void main()
{
double dkm,dm,dcm,dft,din;
clrscr();
printf("Enter Distance in KM");
scanf("%lf",&dkm);
dm=dkm*1000;
dcm=dm*100;
din=dcm*0.3937;
dft=dcm*0.0328;
printf("Distance in CM = %lf\n",dcm);
printf("Distance in Inches = %lf\n",din);
printf("Distance in Feet = %lf\n",dft);
printf("Distance in Meter = %lf",dm);
getch();
}
Download Source Code
Sunday, 15 June 2025
C Programming Solved Problems Let us C Yashwant Kanitkar Chapter 1
Q: (a) Ramesh’s basic salary is input through the keyboard. His dearness
allowance is 40% of basic salary, and house rent allowance is 20% of
basic salary. Write a program to calculate his gross salary.
Solution:
/*(a) Ramesh’s basic salary is input through the keyboard. His dearness
allowance is 40% of basic salary, and house rent allowance is 20% of
basic salary. Write a program to calculate his gross salary.*/
#include<stdio.h>
#include<conio.h>
void main()
{
double b_sal,da,hra,g_sal;
clrscr();
printf("Enter basic salary");
scanf("%lf",&b_sal);
hra=0.20*b_sal;//House Rent Allowance
da=0.40*b_sal;//Dearness Allowance
g_sal=b_sal+da+hra;//Gross Salary
printf("Gross Salary = %lf",g_sal);
getch();
}
Output:Download Source Code
Page : 1 2 3 4 5
Sunday, 19 January 2025
UGC NET COMPUTER SCIENCE AND APPLICATIONS PAPER - 2 Question 2 November 2017 Solution
Q: 2 Let
m=(313)4 and n=(322)4 . Find the base 4 expansion of m+n.
(1) (635)4
(2)
(32312)4
(3)
(21323)4
(4) (1301)4
Answer: (4)
Explanation:
Firstly convert m & n into base 10:
(313)4
= 3*42+1*41+3*40 = (55)10
(322)4 = 3*42+2*41+2*40 = (58)10
Now m + n = 55+58 = (113)10
Now Convert
(113)10 into base 4
- When 113 is
divided by 4, the quotient is 28 and the remainder is 1.
- When 28 is
divided by 4, the quotient is 7 and the remainder is 0.
- When 7 is
divided by 4, the quotient is 1 and the remainder is 3.
- When 1 is
divided by 4, the quotient is 0 and the remainder is 1.
Write the remainders from
bottom to top.
So, (113)10 = (1301)4 which is Correct.
UGC NET COMPUTER SCIENCE AND APPLICATIONS PAPER - 2 Question 1 November 2017 Solution
UGC NET COMPUTER SCIENCE AND APPLICATIONS PAPER - 2 November 2017 Solution
Q: 1 If the time is now 4 O’clock, what will be the time after 101 hours from now ?
(1) 9 O’clock (2) 8 O’clock (3) 5 O’clock (4) 4 O’clock
Answer: (1)
- First, calculate the remainder when 101 is divided by 12:
Quotient is 8 and Remainder is 5 - Now add this remainder to the current time:
i.e. 4+5 = 9Thus, 101 hours from 4 o’clock will be 9 o’clock.The correct answer is (1) 9 O’clock.
Thursday, 2 January 2025
Find All Triplets with Zero Sum
Problem Explanation: Find All Triplets with Zero Sum
The task is to find all unique triplets in an array that add up to zero. A triplet consists of three numbers, and the sum of these three numbers should be zero. For example:
Input: [-1, 0, 1, 2, -1, -4]
Output: [[-1, -1, 2], [-1, 0, 1]]
Approach to Solve the Problem
Sort the Array:
First, sort the array in ascending order. Sorting helps to efficiently find the triplets using two pointers.Fix One Element:
Iterate through the array and fix one element. For each fixed element, find two other elements (using two pointers) such that their sum equals the negative of the fixed element.Use Two Pointers:
After fixing one element, use two pointers:- One pointer starts just after the fixed element.
- The other pointer starts at the end of the array.
- Move the pointers closer based on whether the current sum is less than, equal to, or greater than zero.
Avoid Duplicates:
Skip duplicate elements to ensure the triplets are unique.Add Valid Triplets:
If the sum of the triplet is zero, add it to the result list.
Solution Code in Java
import java.util.*;
public class ZeroSumTriplets {
public static List<List<Integer>> findTriplets(int[] nums) {
List<List<Integer>> result = new ArrayList<>();
Arrays.sort(nums); // Step 1: Sort the array
for (int i = 0; i < nums.length - 2; i++) {
if (i > 0 && nums[i] == nums[i - 1]) {
continue; // Skip duplicates for the first element
}
int left = i + 1; // Pointer 1
int right = nums.length - 1; // Pointer 2
while (left < right) {
int sum = nums[i] + nums[left] + nums[right];
if (sum == 0) {
result.add(Arrays.asList(nums[i], nums[left], nums[right]));
// Move both pointers and skip duplicates
while (left < right && nums[left] == nums[left + 1]) left++;
while (left < right && nums[right] == nums[right - 1]) right--;
left++;
right--;
} else if (sum < 0) {
left++; // Move the left pointer to increase the sum
} else {
right--; // Move the right pointer to decrease the sum
}
}
}
return result;
}
public static void main(String[] args) {
int[] nums = {-1, 0, 1, 2, -1, -4};
List<List<Integer>> triplets = findTriplets(nums);
System.out.println("Triplets with zero sum: " + triplets);
}
}
Explanation of the Code
- Sorting: The array is sorted to simplify the two-pointer approach.
- Outer Loop: Iterates through the array and fixes one element at a time.
- Inner Logic with Two Pointers:
- Adjusts pointers based on the sum of the triplet.
- Adds valid triplets to the result list while skipping duplicates.
- Output: The program prints all unique triplets with a zero sum.
Complexity
- Time Complexity:
Sorting the array takes , and the two-pointer approach runs in , making the overall complexity . - Space Complexity:
for storing the result list.
This solution is efficient and easy to implement for finding triplets with zero sum.
#datastructure #coding #google #maang #leetcode






