C Programming by RMP Sir
C Programming by RMP Sir
Step- 1: Start
Step- 2: Input the values of a and b.
Step- 3: Process S = a + b.
Step- 4: Output S.
Step- 5: End
return 0;
// Prompt user for the second number }
printf("Enter the second number: ");
// Read the second number Output
scanf("%d", &b);
// Calculate the sum Enter the first number: 100
Enter the second number: 150
S = a + b;
Sum: 250
Subtraction Multiplication
#include <stdio.h> #include <stdio.h>
Sub = a - b; M = a * b;
return 0; return 0;
} }
Q = a / b; R = a % b;
return 0; return 0;
} }
Step- 1: Start
Step- 2: Input values of a and b.
Step- 3: Process avg = (a + b) / 2.
Step- 4: Output avg.
Step- 5: End
C Program Output
avg = (a + b) / 2;
return 0;
}
Step- 1: Start
Step- 2: Read values of A and B.
Step- 3: A>B?
YES: A is larger
NO: B is larger
Step- 4: Display the result.
Step- 5: End
C Program Output
// Compare A and B
if (A > B)
printf("A= %d is larger\n", A);
else
printf("B= %d is larger \n", B);
return 0;
}
Step- 1: Start
Step- 2: Input values of l and h.
Step- 3: Process S = (l * h) / 2.
Step- 4: Output S.
Step- 5: End
C Program Output
S = (l * h) / 2;
return 0;
}
Step- 1: Start
Step- 2: Read values of a, b, and c.
Step- 3: Process S = (a + b + c) / 2.
Step- 4: Process area = sqrt(s * (s - a) *
(s - b) * (s - c)).
Step- 5: Output area.
Step- 6: End
C Program Output
#include <stdio.h> Enter the first side of the triangle: 3
#include <math.h> Enter the second side of the triangle: 4
Enter the third side of the triangle: 5
int main() { Area of the triangle: 6
float a, b, c, s, area;
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
return 0;
}
Step-1: Start.
Step- 2: Input a, b, c.
Step- 3: a>b?
YES: Go to step- 4.
NO: Go to step- 5.
Step- 4: a>c?
YES: Output a.
NO: Go to step- 5.
Step- 5: b>c?
YES: Output b.
NO: Output c.
Step- 6: End
C Program Output
#include <stdio.h> Enter the value of a: 5
Enter the value of b: 7
int main() Enter the value of c: 6
The largest number is b (7)
{
int a, b, c;
return 0;
}
11. & 12: C Programs for the conversion of temperature from Celsius to
Fahrenheit and vice-versa.
Algorithm Flow Chart
Step- 1: Start
Step- 2: Input Celsius value, c.
Step- 3: Process f = (9 * c) / 5 + 32.
Step- 4: Output f.
Step- 5: End
return 0;
}
C Program Fahrenheit to Celsius Output
#include <stdio.h>
Temperature in Fahrenheit: 98
int main() { Enter temperature in Celsius: 36.67
float c, f;
return 0;
}
Step- 1: Start
Step- 2: Input A.
Step- 3: Process R= A mod 2;
Step- 4: R==0?
YES: A is Even.
NO: A is Odd.
Step- 5: Output result.
Step- 5: End
C Program Output
return 0;
Step- 1: Start
Step- 2: Input N.
Step- 3: N>=0?
YES: N is Positive.
NO: N is Negative.
Step- 5: Output result.
Step- 5: End
C Program Output
#include<stdio.h> -5
-5 is negative
void main( )
{
int N ;
scanf( “%d”, &N);
if (N>=0)
printf(“%d is Positive”, N);
else
printf(“%d is Negative”, N);
return 0;
Step- 1: Start.
Step- 2: Input a, b.
Step- 3: Process Z= a mod b.
Step- 4: Process a= b.
Step- 5: b= Z.
Step- 6: Z= 0?
YES: Output b.
NO: Return to Step- 4.
Step- 7: End.
C Program Output
#include <stdio.h> 12
8
int main() 4
{
int a, b, Z;
scanf("%d %d", &a, &b);
do
{
Z = a % b;
a = b;
b = Z;
}
while(b != 0);
printf("%d", b);
return 0;
}
16. A C Program with algorithm and flow chart to determine the LCM
of two numbers.
Step- 1: Start.
Step- 2: Input two integers, x and y.
Step- 3: Initialize a variable L with the
maximum value of x and y.
Step- 4: Check if L is divisible by both x
and y.
YES: L is the LCM of a and b,
and go to Step- 5.
NO: increment L by 1 and repeat
Step- 4.
Step- 5: Output the LCM.
Step- 6: End.
C Program Output
#include <stdio.h> Enter two integers: 12
5
int main() { The LCM of 12 and 5 is 60
int x, y, L, lcm;
return 0;
}
17. A C Program with algorithm and flow chart to determine the given
year is a Leap Year or Not.
Step- 1: Start.
Step- 2: Input Year, Y.
Step- 3: Y%400==0?
YES: Go to Step- 6.
NO: Go to Step- 4.
Step- 4: Y%100!=0 && Y%4==0?
YES: Go to Step- 5.
NO: Go to Step- 6.
Step- 5: Output “Not Leap Year”.
Step- 6: Output “Leap Year”.
Step- 7: End.
C Program Output
#include<stdio.h> 2000
2000 is Leap Year
int main( )
{
int Y ;
scanf(“%d”,&Y);
if(Y%400==0||(Y%100!=
0&&Y%4==0))
printf(“%d is Leap Year”, Y);
else
printf(“%d is Not Leap Year”, Y);
getch( );
}
C Program Output
{
float pi, r, area, c;
pi= 3.1416;
printf(“Enter the Radius of the Circle:
”);
scanf(“%f”, &r);
area= pi*r*r;
c= 2*pi*r;
printf(“The Area of the Circle is %f”,
area);
printf(“The Circumference of the
Circle is %f”, c);
19. A C Program with Algorithm and Flow Chart to Find the Series
1+2+3+……..+ N (upto any number)
Step- 1: Start.
Step- 2: Input the value of N.
Step- 3: Let, S= 0, i= 1.
Step- 4: Process S = S + i.
Step- 5: Process i= i+1.
Step- 6: i<=N?
YES: Go to Step- 4.
NO: Output S.
Step- 7: End
C Program Output
return 0;
}
C Program Output
return 0;
}
C Program Output
return 0;
}
C Program Output
return 0;
}
C Program Output
return 0;
}
C Program Output
return 0;
}
C Program Output
#include <stdio.h>
1
int main() 22
{ 333
int i, j; 4444
55555
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= i; j++)
{
printf("%d ", i);
}
printf("\n");
}
return 0;
}
Step- 1: Start.
Step- 2: Input the value of N.
Step- 3: Let, F= 1, i= 1.
Step- 4: Process F = F * i.
Step- 5: Process i= i+1.
Step- 6: i<=N?
YES: Go to Step- 4.
NO: Output F.
Step- 7: End
C Program Output
return 0;
}
{ {
int i; int i = 1;
for (i = 1; i <= 100; i++) while (i <= 100)
{ {
printf("%d\n", i); printf("%d\n", i);
} i++;
}
return 0;
return 0;
}
}
#include <stdio.h> 1
2
int main() 3
4
{ 5
int i = 1; 6
do { 7
printf("%d\n", i); 8
i++; 9
} 10
while (i <= 100); .
.
return 0; .
.
} 98
99
100