Programming
Tuesday, December 27, 2022
What is Java Loop
Friday, December 4, 2020
Write a C program that accepts principle, rate of interest, time and compute the simple interest.
/*Write a C program that
accepts principle, rate of
interest, time and compute
the simple interest.
Test Data:
Input Data: p = 10000,
r = 10% , t = 12 year
Expected Output:
Input principle, Rate of
interest & time to find
simple interest:
Simple interest = 12000
*/
#include <stdio.h>
int main()
{
int p,r,t,interest;
printf("p = ");
scanf("%d",&p);
printf("r = ");
scanf("%d",&r);
printf("t = ");
scanf("%d",&t);
interest=((r*p*t)/100);
printf("Simple interest:\
%d\n",interest);
return 0;
}
Write a C program that accepts a distance in centimeters and prints the corresponding value in inches.
/*Write a C program that
accepts a distance in
centimeters and
prints the corresponding
value in inches.
Test Data:
Input Data: 500cms
Input the distance in cm:
Distance of 500.00 cms is =
196.85 inches
*/
#include <stdio.h>
#define cms 2.54
int main()
{
float cm,result;
printf("Input the distance\
in cm: ");
scanf("%f",&cm);
result=(cm/cms);
printf("Distance of %.2f \
\ncms is = %.2f inches",cm,
result);
return 0;
}
Sunday, November 29, 2020
Write a C program that reads two integers p and q, print p number of lines in a sequence of 1 to q in a line.
/*Write a C program that reads
two integers p and q, print
p number of lines in a
sequence of 1 to q in a line.
Test Data :
Input number of lines: 5
Number of characters in a
line: 6
Expected Output:
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
19 20 21 22 23 24
25 26 27 28 29 30
*/
#include <stdio.h>
int main()
{
int num1,num2,i,j,k=1;
printf("Input the number\
number of lines: ");
scanf("%d",&num1);
printf("Number of character\
in a line: ");
scanf("%d",&num2);
for(i=0;i<num1;i++)
{
for(j=0;j<num2;j++)
{
printf("%d ",k++);
}
j=0;
printf("\n");
}
return 0;
}
Saturday, November 28, 2020
Write a C program to print 3 numbers in a line, starting from 1 and print n lines. Accept number of lines (n, integer) from the user.
/*Write a C program to print
3 numbers in a line, starting
from 1 and print n lines.
Accept number of lines (n,
integer) from the user.
Test Data :
Input number of lines: 5
Expected Output:
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
*/
#include <stdio.h>
int main()
{
int i,num,x=1,j;
printf("Input number of \
line: ");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
for(j=0;j<3;j++)
{
printf("%d \t",x++);
}
j=0;
printf("\n");
}
return 0;
}
Write a C program to find all numbers which are dividing by 7 and the remainder is equal to 2 or 3 between two given integer numbers.
/*Write a C program to find all
numbers which are dividing by
7 and the remainder is equal
to 2 or 3 between two given
integer numbers.
Test Data :
Input the first integer: 25
Input the second integer: 45
Expected Output:
30
31
37
38
44
*/
#include <stdio.h>
int main()
{
int num1,num2,sum=0,i;
printf("Input the first\
number: ");
scanf("%d",&num1);
printf("Input the second\
number: ");
scanf("%d",&num2);
if(num1>num2)
{
int temp=num1;
num1=num2;
num2=temp;
}
for(i=num1;i<num2;i++)
{
if(((i%7)==2)||((i%7)==3))
{
printf("%d\n",i);
}
}
return 0;
}
Thursday, November 26, 2020
Write a C program to read the coordinates(x, y) (in Cartesian system) and find the quadrant to which it belongs (Quadrant -I,Quadrant -II, Quadrant -III, Quadrant -IV). Note: A Cartesian coordinate system is a coordinate system that specifies each point uniquely in a plane by a pair of numerical coordinates. These are often numbered from 1st to 4th and denoted by Roman numerals: I (where the signs of the (x,y) coordinates are I(+,+), II (−,+), III (−,−), and IV (+,−).
Write a C program to read
the coordinates(x, y) (in
Cartesian system) and find
the quadrant to which it
belongs (Quadrant -I,Quadrant
-II, Quadrant -III, Quadrant
-IV).
Note: A Cartesian coordinate
system is a coordinate system
that specifies each point
uniquely in a plane by a
pair of numerical coordinates.
These are often numbered
from 1st to 4th and denoted
by Roman numerals: I (where
the signs of the (x,y)
coordinates are I(+,+),
II (−,+), III (−,−), and
IV (+,−).
Test Data :
Input the Coordinate(x,y):
x: 25
y: 15
Expected Output:
Quadrant-I(+,+)
*/
#include <stdio.h>
int main()
{
int x,y,z=0;
while(z=1)
{
printf("Input the Coord\
inate(x,y):\n");
printf("x: ");
scanf("%d",&x);
printf("y: ");
scanf("%d",&y);
if(x>=0 && y>=0)
{
printf("quadrant -I(+,+)\n");
}
else if(x<=0 && y>=0)
{
printf("quadrant -II(-,+)\n");
}
else if(x<=0 && y<=0)
{
printf("quadrant -III(-,-)\n");
}
else if(x>=0 && y<=0)
{
printf("quadrant -IV(+,-)\n");
}
break;
}
return 0;
}