0% found this document useful (0 votes)
0 views3 pages

Problem Solving Techniques Lab

The document contains examples of C programs demonstrating sequential structures and selective controls. It includes programs for converting Fahrenheit to Celsius, summing digits of a number, finding the greatest of three numbers, checking if a number is even or odd, and determining a student's grade based on marks. Each program is accompanied by code snippets illustrating the implementation of the respective functionality.

Uploaded by

manoj322007
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)
0 views3 pages

Problem Solving Techniques Lab

The document contains examples of C programs demonstrating sequential structures and selective controls. It includes programs for converting Fahrenheit to Celsius, summing digits of a number, finding the greatest of three numbers, checking if a number is even or odd, and determining a student's grade based on marks. Each program is accompanied by code snippets illustrating the implementation of the respective functionality.

Uploaded by

manoj322007
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/ 3

PROBLEM SOLVING TECHNIQUES LAB

1. SIMPLE EXAMPLES ON SEQUENTIAL STRUCTURE WITH


OPERATORS
a. To write a C program to convert Fahrenheit to Celsius

#include<stdio.h>
main()
{ float fah, cel;
printf ("Enter temperature in Fahrenheit scale : ");
scanf ("%f", &fah);
cel = 5*(fah-32)/9;
printf("%f Fahrenheit = %f Celsius\n", fah, cel);
}

b. To write a C program to find the sum of individual digits of a


given number.

//Program to find the sum of digits of a 3-digit number


#include<stdio.h>
main()
{ int num, sum;
printf("Enter a 3-digit number : ");
scanf("%d" , &num);
sum = num/100;
num=num%100;
sum=sum+num/10;
num=num%10;
sum=sum+num;
printf("Sum of digits = %d\n" , sum);
}

c. To write a C program that calculates the area of a rectangle


?????
2. PROGRAMS USING SELECTIVE CONTROLS
a. To write a C program to find the greatest of three numbers
#include<stdio.h>
int main()
{
int a, b,c;
printf(“\n Enter the first number: “);
scanf(“%d”, &a);
printf(“\n Enter the second number: “);
scanf(“%d”, &b);
printf(“\n Enter the third number: “);
scanf(“%d”, &c);
if(a > b) {
if(a > c) {
printf("\nGreatest is: %d", a);
} else {
printf("\nGreatest is: %d", c);
}
} else if(b > c) {
printf("\nGreatest is: %d", b);
} else {
printf("\nGreatest is: %d", c);
}
return 0;
}

b. To write a C Program to check whether a number is even or


odd

#include <stdio.h>

int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);

if (num % 2 == 0) {
printf("%d is even.\n", num);
} else {
printf("%d is odd.\n", num);
}

return 0;
}

c. To write a C Program to print the grade of a Student

#include <stdio.h>
int main() {
float marks;
printf("Enter your marks (out of 100): ");
scanf("%f", &marks);
if (marks >= 90) {
printf("Grade: A\n");
} else if (marks >= 80 && marks < 90) {
printf("Grade: B\n");
} else if (marks >= 70 && marks < 80) {
printf("Grade: C\n");
} else if (marks >= 60 && marks < 70) {
printf("Grade: D\n");
} else {
printf("Grade: F (Failed)\n");
}

return 0;
}

d. To write a C program to check whether the given number is


positive or not

You might also like