Introduction to programming in C Week 1
Course Name: Introduction to programming in C
Course Link: Click Here
These are Introduction to programming in C Assignment 1 Answers
Question 1
You have a certain number of 100 rupee notes, 10 rupee notes and 1 rupee notes with you.
There is an item you want to buy whose price is given to you.
Write a program to find if the item is affordable, that is the price of the item is less than or equal to the current money you have.
Input
—–
Four non negative integers.
The first input is an integer representing the number of 100 rupee notes.
The second input is an integer representing the number of 10 rupee notes.
The third input is an integer representing the number of 1 rupee notes.
The fourth input is an integer representing the price of the item.
Output
——
You have to output 1 if the item is affordable.
You have to output 0 if the item is not affordable.
Solution:
#include <stdio.h>
void main()
{
int h, t, o, price,current_money;
scanf("%d %d %d %d", &h, &t, &o, &price);
current_money = 100*h+10*t+o;
if(price <= current_money)
printf("1");
else
printf("0");
}
These are NPTEL Introduction to programming in C Assignment 1 Answers
Question 2
You are given two positive integers, say M and N.
Check whether M is an exact multiple of N, without using loops.
Input
—–
Two positive integers, say M and N.
Output
——
You have to output 0 if M is not a multiple of N.
You have to output 1 if M is a multiple of N.
Solution:
#include <stdio.h>
void main()
{
int m,n;
scanf("%d %d", &m, &n);
if(m % n)
printf("0");
else
printf("1");
}
These are Introduction to programming in C Assignment 1 Answers
Question 3
Given three integers a b and c, find if they are strictly increasing/decreasing or not.
Input
——-
Triplet of three integers (a,b,c)
Output
———
You have to output 1 if they are either in strictly increasing (a>b>c) or decreasing (a<b<c) order.
Output 0, otherwise.
Solution:
#include <stdio.h>
int main()
{
int a,b,c;
scanf("%d %d %d", &a,&b, &c);
if(((a>b) && (b>c))||((c>b) && (b>a)))
{
printf("1");
}
else
printf("0");
return 0;
}
These are Introduction to programming in C Assignment 1 Answers
More Solutions of Introduction to programming in C: Click Here
More NPTEL Solutions: https://progiez.com/answers/nptel/

This content is uploaded for study, general information, and reference purpose only.