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

Problem Solving Through Programming in C Week 4 Programming Assignment

The document contains programming assignments from an online course on problem solving through programming in C. It includes the instructions and solutions for 4 assignments: 1) Write a program to find the smallest of three numbers using nested if-else statements, 2) Write a program to determine the type of triangle based on lengths of three sides, 3) Write a program to calculate the sum of all even numbers from 1 to a given number N, 4) Write a program to calculate power of a number using a while loop.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
432 views

Problem Solving Through Programming in C Week 4 Programming Assignment

The document contains programming assignments from an online course on problem solving through programming in C. It includes the instructions and solutions for 4 assignments: 1) Write a program to find the smallest of three numbers using nested if-else statements, 2) Write a program to determine the type of triangle based on lengths of three sides, 3) Write a program to calculate the sum of all even numbers from 1 to a given number N, 4) Write a program to calculate power of a number using a while loop.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

NPTEL » Problem solving through Programming In C

https://www.youtube.com/channel/UCmt2xnmpmOmhiaB2BRqdLDA

Week 4: Programming Assignment 1


Due on 2021-09-02, 23:59 IST
Write a C Program to Find the Smallest Number among Three Numbers (integer values)
using Nested IF-Else statement.
SOLUTION
if((n1<n2)&&(n1<n3))
printf("%d is the smallest number. ", n1);
else if(n2<n3)
printf("%d is the smallest number.", n2);
else
printf("%d is the smallest number.", n3);

}
NPTEL » Problem solving through Programming In C
https://www.youtube.com/channel/UCmt2xnmpmOmhiaB2BRqdLDA

Week 4: Programming Assignment 2


Due on 2021-09-02, 23:59 IST
The length of three sides are taken as input. Write a C program to find whether a triangle can be formed or not.
If not display “This Triangle is NOT possible.” If the triangle can be formed then check whether the triangle
formed is equilateral, isosceles, scalene or a right-angled triangle. (If it is a right-angled triangle then only print
Right-angle triangle do not print it as Scalene Triangle or Isosceles triangle).

SOLUTION
if(a<(b+c)&&b<(a+c)&&c<(a+b))

if(a==b&&a==c&&b==c)

printf("Equilateral Triangle");

else if(a==b||a==c||b==c)

printf("Isosceles Triangle");

else if((a*a )==(b*b)+(c*c)||(b*b)==(a*a)+(c*c)||(c*c)==(a*a)+(b*b))

printf("Right-angle Triangle");

else if( a != b && a != c && b != c )

printf("Scalene Triangle");

else

printf("Triangle is not possible");

return 0 ;

}
NPTEL » Problem solving through Programming In C
https://www.youtube.com/channel/UCmt2xnmpmOmhiaB2BRqdLDA

Week 4: Programming Assignment 3


Due on 2021-09-02, 23:59 IST
Write a Program to find the sum of all even numbers from 1 to N where the value of N is taken as input. [For
example when N is 10 then the sum is 2+4+6+8+10 = 30]

SOLUTION

for(int i=2;i<=N;i=i+2)
sum+=i;

printf("Sum = %d",sum);
}
NPTEL » Problem solving through Programming In C
https://www.youtube.com/channel/UCmt2xnmpmOmhiaB2BRqdLDA

Week 4: Programming Assignment 4


Due on 2021-09-02, 23:59 IST
Write a C program to find power of a number using while loops. The base number (>0) and exponent (>=0) is
taken from the test cases.

SOLUTION

if(exponent==0)
result=1;
else
result=base;
for(int i=1;i<exponent;i++)
result=result*base;

You might also like