0% found this document useful (0 votes)
48 views

Some Important Coding Practice

Here have some important code like batsman strike rate showing by the c programming , farhrenheit to degree or something celsius etc .
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Some Important Coding Practice

Here have some important code like batsman strike rate showing by the c programming , farhrenheit to degree or something celsius etc .
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

CSE 104

Structure Programming
Language – Lab Manual

Sheikh Shahariar Rumi


Ahmed Iqbal Pritom
I’d : 201002326

21 - 10 - 2020
20 - 10 - 2020
All Question
Ans to the Question
no : 1
Input :
#include <stdio.h>
int main()
{
int first, second, add, subtract, multiply;
float divide;

printf(“Enter two integers\n”);


scanf(“%d%d”, &first, &second);
add = first + second;
subtract = first – second;
multiply = first * second;
divide = first / (float)second;
printf(“Sum = %d\n”,add);
printf(“Difference = %d\n”,subtract);
printf(“Multiplication = %d\n”,multiply);
printf(“Division = %.2f\n”,divide);

return 0; Output :
}
Ans to the Question no. 2
Input :

#include<stdio.h>
void main ()
{

int ball, run;


float strike_rate;

printf (“Enter the run:”);


scanf(“%d”, &run);
printf(“Enter the ball:”);
scanf (“%d”, &ball);

strike_rate = ( run / ball ) * 100 ;


printf (“The strike rate is: %f”, strike_rate);

Output :
Ans. To the Question No: 3

Input :
#include <stdio.h>
int main() {
int n, rev = 0, remainder;
printf(“Enter an integer: “);
scanf(“%d”, &n);
while (n != 0)
{ remainder = n %
10;
rev = rev * 10 + remainder;
n /= 10;
}
printf(“Reversed number = %d”, rev);
return 0;
}

Output :
Ans. To the Question No : 4
Input with third veriable :
#include <stdio.h>
int main()
{
int a, b, c;

printf(“Enter two integers\n”);


scanf(“%d%d”, &a, &b);

printf(“Before Swapping\nFirst integer = %d\nSecond integer = %d\n”, a, b);

c = a;
a = b;
b = c;

printf(“After Swapping\nFirst integer = %d\nSecond integer = %d\n”, a, b);

return
0; }
Output :
Input without third veriable :
#include<stdio.h>
int main()
{
int a, b;
printf(“Input value for a & b: \n”);
scanf(“%d%d”,&a,&b);
printf(“Before swapping the value of a & b: %d %d”,a,b);
a=a+b;
b=a-b;
a=a-b;
printf(“\nAfter swapping the value of a & b: %d %d”,a,b);
return 0;
}

Output :
Ans. To the Question No : 5
Input :

#include <stdio.h>

int main()
{
float celsius, fahrenheit;

printf(“Enter temperature in Fahrenheit: “);


scanf(“%f”, &fahrenheit);

celsius = (fahrenheit – 32) * 5 / 9;

printf(“%.2f Fahrenheit = %.2f Celsius”, fahrenheit, celsius);

return
0; }
Output :
Ans . To the Question No : 6
Input :
#include <stdio.h>
int main() {
int sec, h, m, s;
printf(“Input seconds: “);
scanf(“%d”, &sec);

h = (sec/3600);

m = (sec –(3600*h))/60;

s = (sec –(3600*h)-(m*60));

printf(“H:M:S - %d:%d:%d\n”,h,m,s);

return
0; }
Output :
Ans. To the Question No : 7

Input :
#include<stdio.h>
#include<string.h>
int main(){
char str[25];
int I;
printf(“Enter the string: “);
scanf(“%s”,str);
for(i=0;i<=strlen(str);i++){
if(str[i]>=65&&str[i]<=90)
str[i]=str[i]+32;
}
printf(“\nLower Case String is: %s”,str);
return 0 ;
}
Output :
Ans. To the Question No : 8

Input :
#include <stdio.h>
#include <math.h>

int main() {
float x1, y1, x2, y2, gdistance;
printf(“Input x1: “);
scanf(“%f”, &x1);
printf(“Input y1: “);
scanf(“%f”, &y1);
printf(“Input x2: “);
scanf(“%f”, &x2);
printf(“Input y2: “);
scanf(“%f”, &y2);
gdistance = ((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1));
printf(“Distance between the said points: %.4f”, sqrt(gdistance));
printf(“\n”);
return 0;
} Output :
Ans. To the Question No : 9
Input :
#include <stdio.h>
int main() {
char c;
printf(“Enter a character: “);
scanf(“%c”, &c);
printf(“ASCII value of %c = %d”, c, c);

return
0; }
Output :
Ans. To the Question No 10
Input :
#include <math.h>
#include <stdio.h>
int main() {
double a, b, c, discriminant, root1, root2, realPart,
imagPart;
printf(“Enter coefficients a, b and c: “);
scanf(“%lf %lf %lf”, &a, &b, &c);

discriminant = b * b – 4 * a * c;

if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b – sqrt(discriminant)) / (2 * a);
printf(“root1 = %.2lf and root2 = %.2lf”, root1,
root2); }
else if (discriminant == 0)
{ root1 = root2 = -b / (2 *
a);
printf(“root1 = root2 = %.2lf;”,
root1); }

else {
realPart = -b / (2 * a);
imagPart = sqrt(-discriminant) / (2 * a);
printf(“root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi”,
realPart, imagPart, realPart,
imagPart); }

return
0; }
Output :

You might also like