Some Important Coding Practice
Some Important Coding Practice
Structure Programming
Language – Lab Manual
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;
return 0; Output :
}
Ans to the Question no. 2
Input :
#include<stdio.h>
void main ()
{
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;
c = a;
a = b;
b = c;
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;
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 :