swayam-logo

Problem Solving Through Programming In C

  • Formulate simple algorithms for arithmetic and logical problems
  • Translate the algorithms to programs (in C language)
  • Test and execute the programs and  correct syntax and logical errors
  • Implement conditional branching, iteration and recursion
  • Decompose a problem into functions and synthesize a complete program using divide and conquer approach
  • Use arrays, pointers and structures to formulate algorithms and programs
  • Apply programming to solve matrix addition and multiplication problems and searching and sorting problems 
  • Apply programming to solve simple numerical method problems, namely rot finding of function, differentiation of function and simple integration

Note: This exam date is subjected to change based on seat availability. You can check final exam date on your hall ticket.

Page Visits

Course layout, books and references, instructor bio.

assignment problem in c program

Prof. Anupam Basu

Course certificate.

  • Assignment score = 25% of average of best 8 assignments out of the total 12 assignments given in the course. 
  • ( All assignments in a particular week will be counted towards final scoring - quizzes and programming assignments). 
  • Unproctored programming exam score = 25% of the average scores obtained as part of Unproctored programming exam - out of 100
  • Proctored Exam score =50% of the proctored certification exam score out of 100

assignment problem in c program

DOWNLOAD APP

assignment problem in c program

SWAYAM SUPPORT

Please choose the SWAYAM National Coordinator for support. * :

  • Machine Learning Decision Tree – Solved Problem (ID3 algorithm)
  • Poisson Distribution | Probability and Stochastic Process
  • Conditional Probability | Joint Probability
  • Solved assignment problems in communicaion |online Request
  • while Loop in C++

EngineersTutor

Solved assignment problems in c – part1.

Q1 . Create a program to compute the volume of a sphere. Use the formula: V = (4/3) *pi*r 3 where pi is equal to 3.1416 approximately. The r is the radius of sphere.  Display the result.

Sol :    #include<stdio.h> #define pi 3.1416 void main() { //we need to give only one input to program i.e., radius of sphere r     int r;   float vol; printf(“Enter radius of sphere:\n”); scanf(“%d”, &r); vol = (4/3)*pi*r*r*r; printf(“Volume of sphere is: %f”, vol); }

Q2 . Write a program the converts the input Celsius degree into its equivalent Fahrenheit degree. Use the formula: F = (9/5) *C+32.

Sol : include<stdio.h> void main() { //need only one input to program i.e., temperature in Celsius float C; float Fh; printf(“Enter temperature in Celsius:\n”); scanf(“%f”, &C); Fh = (1.8*C)+32; printf(“Converted Fahrenheit value is: %f”, Fh); }

Q3 . Write a program that converts the input dollar to its peso exchange rate equivalent.  Assume that the present exchange rate is 51.50 pesos against the dollar. Then display the peso equivalent exchange rate.

Sol: include<stdio.h> void main() { //need only one input to program i.e., Number of Dollars float dollar; float peso; printf(“Enter amount of dollars to convert:\n”); scanf(“%f”, &dollar); peso = dollar*51.50; printf(“Equivalent peso is: %f”, peso); }

Q4 . Write a program that converts an input inch(es) into its equivalent centimeters. Take note that one inch is equivalent to 2.54cms.

Sol : include<stdio.h> void main() { //we need to give only one input to program i.e., inches float inch; float cm; printf(“Enter inches:\n”); scanf(“%f”, &inch);cm = 2.54* inch; printf(“Equivalent peso is: %f”, cm); }

Q5 . Write a program that exchanges the value of two variables: x and y.  The output must be: the value of variable y will become the value of variable x, and vice versa.

Sol : include<stdio.h> void main() { //we need to give 2 inputs: x and y; int x, y; int z; printf(“Enter values of x and y:\n”); scanf(“%d %d”, &x, &y); printf(“Before swapping, values of x and y are: %d %d”, x, y); printf(“\n”);z = x;x = y;y =z; printf(“After swapping, values of x and y are: %d %d”, x, y); }

  • ← FM sidebands | AM/FM comparison | Homework questions
  • Solved Assignment Problems in C++ – Part1 →

Gopal Krishna

Hey Engineers, welcome to the award-winning blog,Engineers Tutor. I'm Gopal Krishna. a professional engineer & blogger from Andhra Pradesh, India. Notes and Video Materials for Engineering in Electronics, Communications and Computer Science subjects are added. "A blog to support Electronics, Electrical communication and computer students".

' src=

You May Also Like

Pointers in c, hierarchy of operators in c, solved assignment problems in c (with algorithm and flowchart), leave a reply cancel reply.

Your email address will not be published. Required fields are marked *

Browse Course Material

Course info, instructors.

  • Daniel Weller
  • Sharat Chikkerur

Departments

  • Electrical Engineering and Computer Science

As Taught In

  • Programming Languages
  • Software Design and Engineering

Learning Resource Types

Practical programming in c, assignments.

facebook

You are leaving MIT OpenCourseWare

CProgramming Tutorial

  • C Programming Tutorial
  • C - Overview
  • C - Features
  • C - History
  • C - Environment Setup
  • C - Program Structure
  • C - Hello World
  • C - Compilation Process
  • C - Comments
  • C - Keywords
  • C - Identifiers
  • C - User Input
  • C - Basic Syntax
  • C - Data Types
  • C - Variables
  • C - Integer Promotions
  • C - Type Conversion
  • C - Booleans
  • C - Constants
  • C - Literals
  • C - Escape sequences
  • C - Format Specifiers
  • C - Storage Classes
  • C - Operators
  • C - Arithmetic Operators
  • C - Relational Operators
  • C - Logical Operators
  • C - Bitwise Operators
  • C - Assignment Operators
  • C - Unary Operators
  • C - Increment and Decrement Operators
  • C - Ternary Operator
  • C - sizeof Operator
  • C - Operator Precedence
  • C - Misc Operators
  • C - Decision Making
  • C - if statement
  • C - if...else statement
  • C - nested if statements
  • C - switch statement
  • C - nested switch statements
  • C - While loop
  • C - For loop
  • C - Do...while loop
  • C - Nested loop
  • C - Infinite loop
  • C - Break Statement
  • C - Continue Statement
  • C - goto Statement
  • C - Functions
  • C - Main Functions
  • C - Function call by Value
  • C - Function call by reference
  • C - Nested Functions
  • C - Variadic Functions
  • C - User-Defined Functions
  • C - Callback Function
  • C - Return Statement
  • C - Recursion
  • C - Scope Rules
  • C - Static Variables
  • C - Global Variables
  • C - Properties of Array
  • C - Multi-Dimensional Arrays
  • C - Passing Arrays to Function
  • C - Return Array from Function
  • C - Variable Length Arrays
  • C - Pointers
  • C - Pointers and Arrays
  • C - Applications of Pointers
  • C - Pointer Arithmetics
  • C - Array of Pointers
  • C - Pointer to Pointer
  • C - Passing Pointers to Functions
  • C - Return Pointer from Functions
  • C - Function Pointers
  • C - Pointer to an Array
  • C - Pointers to Structures
  • C - Chain of Pointers
  • C - Pointer vs Array
  • C - Character Pointers and Functions
  • C - NULL Pointer
  • C - void Pointer
  • C - Dangling Pointers
  • C - Dereference Pointer
  • C - Near, Far and Huge Pointers
  • C - Initialization of Pointer Arrays
  • C - Pointers vs. Multi-dimensional Arrays
  • C - Strings
  • C - Array of Strings
  • C - Special Characters
  • C - Structures
  • C - Structures and Functions
  • C - Arrays of Structures
  • C - Self-Referential Structures
  • C - Nested Structures
  • C - Bit Fields
  • C - Typedef
  • C - Input & Output
  • C - File I/O
  • C - Preprocessors
  • C - Header Files
  • C - Type Casting
  • C - Error Handling
  • C - Variable Arguments
  • C - Memory Management
  • C - Command Line Arguments
  • C Programming Resources
  • C - Questions & Answers
  • C - Quick Guide
  • C - Useful Resources
  • C - Discussion
  • Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Effective Resume Writing
  • HR Interview Questions
  • Computer Glossary

Assignment Operators in C

In C language, the assignment operator stores a certain value in an already declared variable. A variable in C can be assigned the value in the form of a literal, another variable, or an expression.

The value to be assigned forms the right-hand operand, whereas the variable to be assigned should be the operand to the left of the " = " symbol, which is defined as a simple assignment operator in C.

In addition, C has several augmented assignment operators.

The following table lists the assignment operators supported by the C language −

Simple Assignment Operator (=)

The = operator is one of the most frequently used operators in C. As per the ANSI C standard, all the variables must be declared in the beginning. Variable declaration after the first processing statement is not allowed.

You can declare a variable to be assigned a value later in the code, or you can initialize it at the time of declaration.

You can use a literal, another variable, or an expression in the assignment statement.

Once a variable of a certain type is declared, it cannot be assigned a value of any other type. In such a case the C compiler reports a type mismatch error.

In C, the expressions that refer to a memory location are called "lvalue" expressions. A lvalue may appear as either the left-hand or right-hand side of an assignment.

On the other hand, the term rvalue refers to a data value that is stored at some address in memory. A rvalue is an expression that cannot have a value assigned to it which means an rvalue may appear on the right-hand side but not on the left-hand side of an assignment.

Variables are lvalues and so they may appear on the left-hand side of an assignment. Numeric literals are rvalues and so they may not be assigned and cannot appear on the left-hand side. Take a look at the following valid and invalid statements −

Augmented Assignment Operators

In addition to the = operator, C allows you to combine arithmetic and bitwise operators with the = symbol to form augmented or compound assignment operator. The augmented operators offer a convenient shortcut for combining arithmetic or bitwise operation with assignment.

For example, the expression "a += b" has the same effect of performing "a + b" first and then assigning the result back to the variable "a".

Run the code and check its output −

Similarly, the expression "a <<= b" has the same effect of performing "a << b" first and then assigning the result back to the variable "a".

Here is a C program that demonstrates the use of assignment operators in C −

When you compile and execute the above program, it will produce the following result −

To Continue Learning Please Login

Codeforwin

Pointer programming exercises and solutions in C

Pointer is a variable that stores memory addresses. Unlike normal variables it does not store user given or processed value, instead it stores valid computer memory address.

Pointer allows various magical things to be performed in C.

  • Pointers are more efficient in handling arrays and structures.
  • Pointers are used to return multiple values from a function.
  • Pointer allows dynamic memory allocation and deallocation (creation and deletion of variables at runtime) in C. Which undoubtedly is the biggest advantage of pointers.
  • Pointer allows to refer and pass a function as a parameter to functions.

and many more…

For beginners pointers can be a bad dream if not practiced well. However, once mastered you can do anything you want to do in C programming language.

In this exercise I will cover most of the pointer related topics from a beginner level. Always feel free to drop your queries and suggestion down below in the comments section .

Pointer to Pointer (Double pointer) memory representation

Required knowledge

Pointers , Pointer Arithmetic , Pointer to Pointer , Pointer and Arrays , Function Pointer

Please go through above tutorials to get a good grasp of following examples.

List of pointer programming exercises

  • Write a C program to create, initialize and use pointers .
  • Write a C program to add two numbers using pointers .
  • Write a C program to swap two numbers using pointers .
  • Write a C program to input and print array elements using pointer .
  • Write a C program to copy one array to another using pointers .
  • Write a C program to swap two arrays using pointers .
  • Write a C program to reverse an array using pointers .
  • Write a C program to search an element in array using pointers .
  • Write a C program to access two dimensional array using pointers .
  • Write a C program to add two matrix using pointers .
  • Write a C program to multiply two matrix using pointers .
  • Write a C program to find length of string using pointers .
  • Write a C program to copy one string to another using pointers .
  • Write a C program to concatenate two strings using pointers .
  • Write a C program to compare two strings using pointers .
  • Write a C program to find reverse of a string using pointers .
  • Write a C program to sort array using pointers .
  • Write a C program to return multiple value from function using pointers .

Learn C practically and Get Certified .

Popular Tutorials

Popular examples, reference materials, learn c interactively, c introduction.

  • Getting Started with C
  • Your First C Program

C Fundamentals

  • C Variables, Constants and Literals
  • C Data Types
  • C Input Output (I/O)
  • C Programming Operators

C Flow Control

  • C if...else Statement
  • C while and do...while Loop
  • C break and continue
  • C switch Statement
  • C goto Statement
  • C Functions
  • C User-defined functions
  • Types of User-defined Functions in C Programming
  • C Recursion
  • C Storage Class

C Programming Arrays

C Multidimensional Arrays

Pass arrays to a function in C

C Programming Pointers

Relationship Between Arrays and Pointers

  • C Pass Addresses and Pointers
  • C Dynamic Memory Allocation
  • C Array and Pointer Examples
  • C Programming Strings
  • String Manipulations In C Programming Using Library Functions
  • String Examples in C Programming

C Structure and Union

  • C structs and Pointers
  • C Structure and Function

C Programming Files

  • C File Handling

C Files Examples

C Additional Topics

  • C Keywords and Identifiers
  • C Precedence And Associativity Of Operators
  • C Bitwise Operators
  • C Preprocessor and Macros
  • C Standard Library Functions

C Tutorials

  • Find Largest Element in an Array
  • Calculate Average Using Arrays
  • Access Array Elements Using Pointer
  • Add Two Matrices Using Multi-dimensional Arrays

C arrays

An array is a variable that can store multiple values. For example, if you want to store 100 integers, you can create an array for it.

How to declare an array?

For example,

Here, we declared an array, mark , of floating-point type. And its size is 5. Meaning, it can hold 5 floating-point values.

It's important to note that the size and type of an array cannot be changed once it is declared.

Access Array Elements

You can access elements of an array by indices.

Suppose you declared an array mark as above. The first element is mark[0] , the second element is mark[1] and so on.

C Array declaration

Few keynotes :

  • Arrays have 0 as the first index, not 1. In this example, mark[0] is the first element.
  • If the size of an array is n , to access the last element, the n-1 index is used. In this example, mark[4]
  • Suppose the starting address of mark[0] is 2120d . Then, the address of the mark[1] will be 2124d . Similarly, the address of mark[2] will be 2128d and so on. This is because the size of a float is 4 bytes.

How to initialize an array?

It is possible to initialize an array during declaration. For example,

You can also initialize an array like this.

Here, we haven't specified the size. However, the compiler knows its size is 5 as we are initializing it with 5 elements.

Initialize an array in C programming

Change Value of Array elements

Input and output array elements.

Here's how you can take input from the user and store it in an array element.

Here's how you can print an individual element of an array.

Example 1: Array Input/Output

Here, we have used a  for loop to take 5 inputs from the user and store them in an array. Then, using another  for loop, these elements are displayed on the screen.

Example 2: Calculate Average

Here, we have computed the average of n numbers entered by the user.

Access elements out of its bound!

Suppose you declared an array of 10 elements. Let's say,

You can access the array elements from testArray[0] to testArray[9] .

Now let's say if you try to access testArray[12] . The element is not available. This may cause unexpected output (undefined behavior). Sometimes you might get an error and some other time your program may run correctly.

Hence, you should never access elements of an array outside of its bound.

Multidimensional arrays

In this tutorial, you learned about arrays. These arrays are called one-dimensional arrays.

In the next tutorial, you will learn about multidimensional arrays (array of an array) .

Table of Contents

  • C Arrays (Introduction)
  • Declaring an Array
  • Access array elements
  • Initializing an array
  • Change Value of Array Elements
  • Array Input/Output
  • Example: Calculate Average
  • Array Elements Out of its Bound

Video: C Arrays

Sorry about that.

Related Tutorials

IMAGES

  1. Solved Assignment Problems in C (with Algorithm and Flowchart

    assignment problem in c program

  2. Solved Assignment Problems in C (with Algorithm and Flowchart

    assignment problem in c program

  3. Assignment Operators in C Example

    assignment problem in c program

  4. C programming +=

    assignment problem in c program

  5. Problem solving through Programming In C||WEEK-6 Assignment Answers

    assignment problem in c program

  6. PPT

    assignment problem in c program

VIDEO

  1. Assignment Problem ( Brute force method) Design and Analysis of Algorithm

  2. NPTEL Problem Solving Through Programming In C || Week 3 || Assignment 3 Solution || Swayam || JAN24

  3. Augmented assignment operators in C

  4. Sum of Subset Problem || C Program || Advanced data structures tutorial in Telugu

  5. NPTEL Problem Solving Through Programming In C Week 0 Quiz Assignment Solution

  6. C++ program to solve assignment problem using hungarian algorithm

COMMENTS

  1. Job Assignment Problem using Branch And Bound

    Solution 1: Brute Force. We generate n! possible job assignments and for each such assignment, we compute its total cost and return the less expensive assignment. Since the solution is a permutation of the n jobs, its complexity is O (n!). Solution 2: Hungarian Algorithm. The optimal assignment can be found using the Hungarian algorithm.

  2. Hungarian Algorithm for Assignment Problem

    Step 3: Cover all zeroes with minimum number of horizontal and vertical lines. Step 4: Since we need 3 lines to cover all zeroes, the optimal assignment is found. 2500 4000 3500 4000 6000 3500 2000 4000 2500. So the optimal cost is 4000 + 3500 + 2000 = 9500. For implementing the above algorithm, the idea is to use the max_cost_assignment() function defined in the dlib library.

  3. C programming Exercises, Practice, Solution

    C is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. C was originally developed by Dennis Ritchie between 1969 and 1973 at Bell Labs.

  4. Assignment Problem and Hungarian Algorithm

    The assignment problem is a special case of the transportation problem, which in turn is a special case of the min-cost flow problem, so it can be solved using algorithms that solve the more general cases. Also, our problem is a special case of binary integer linear programming problem (which is NP-hard). But, due to the specifics of the ...

  5. Assignment problem

    The assignment problem is a special case of the transportation problem, which is a special case of the minimum cost flow problem, which in turn is a special case of a linear program. While it is possible to solve any of these problems using the simplex algorithm , each specialization has a smaller solution space and thus more efficient ...

  6. Solved Assignment Problems in C (with Algorithm and Flowchart)

    Solved Assignment Problems in C (with Algorithm and Flowchart) Q1. Create a program to compute the volume of a sphere. Use the formula: V = (4/3) *pi*r 3 where pi is equal to 3.1416 approximately. The r is the radius of sphere. Display the result. Q2.

  7. PDF Solved Assignment Problems in C (with Algorithm and Flowchart)

    Write a program that takes as input the purchase price of an item (P), its expected number of years of service (Y) and its expected salvage value (S). Then outputs the yearly depreciation for the item (D). Use the formula: D = (P - S) Y Algorithm Flowchart Program 1. Start 2. Read P 3.

  8. Problem Solving Through Programming In C

    Learners enrolled: 29073. ABOUT THE COURSE : This course is aimed at enabling the students to. Formulate simple algorithms for arithmetic and logical problems. Translate the algorithms to programs (in C language) Test and execute the programs and correct syntax and logical errors. Implement conditional branching, iteration and recursion.

  9. Solved Assignment Problems in C

    Solved Assignment Problems in C - Part1. October 3, 2020 Gopal Krishna 3250 Views 0 Comments assignment problems in C, C programming. Q1. Create a program to compute the volume of a sphere. Use the formula: V = (4/3) *pi*r 3 where pi is equal to 3.1416 approximately. The r is the radius of sphere. Display the result.

  10. Problem Set 1

    Problem set on writing, compiling, and debugging C programs, preprocessor macros, the C file structure, variables, functions and program statements, ... assignment_turned_in Programming Assignments with Examples. Download Course. Over 2,500 courses & materials

  11. Assignments

    Assignment 3: Problem 1: C++ Linked List Library (PDF) Sample Solution to Assignment 3, Problem 1. Solution and test data: cpplist (ZIP) (This ZIP file contains: 3 .h files, 4 .cpp files, 1 .make file and 1 .txt file.) **Assignment 4 (Final Project) ** Problem: N-Body Gravity Simulation (problem statement available in Lecture Notes for Lecture 8)

  12. C Exercises

    Q2: Write a Program to find the Sum of two numbers entered by the user. In this problem, you have to write a program that adds two numbers and prints their sum on the console screen. For Example, Input: Enter two numbers A and B : 5 2. Output: Sum of A and B is: 7.

  13. Operators in C

    C programming has two operators increment ++ and decrement -- to change the value of an operand (constant or variable) by 1. Increment ++ increases the value by 1 whereas decrement -- decreases the value by 1. These two operators are unary operators, meaning they only operate on a single operand.

  14. If else programming exercises and solutions in C

    Write a C program to find maximum between three numbers. Write a C program to check whether a number is negative, positive or zero. Write a C program to check whether a number is divisible by 5 and 11 or not. Write a C program to check whether a number is even or odd. Write a C program to check whether a year is leap year or not.

  15. Assignments

    Practical Programming in C. Menu. More Info Syllabus Calendar Lecture Notes ... compiling, and debugging programs; preprocessor macros; C file structure; variables; functions and problem statements; returning from functions 2 Types, operators, expressions ... assignment_turned_in Programming Assignments with Examples. Download Course.

  16. Loop programming exercises and solutions in C

    List of loop programming exercises. Write a C program to print all natural numbers from 1 to n. - using while loop. Write a C program to print all natural numbers in reverse (from n to 1). - using while loop. Write a C program to print all alphabets from a to z. - using while loop.

  17. Assignment Operators in C

    Simple assignment operator. Assigns values from right side operands to left side operand. C = A + B will assign the value of A + B to C. +=. Add AND assignment operator. It adds the right operand to the left operand and assign the result to the left operand. C += A is equivalent to C = C + A. -=.

  18. C Pointers (With Examples)

    Explanation of the program. int* pc, c; Here, a pointer pc and a normal variable c, both of type int, is created. Since pc and c are not initialized at initially, pointer pc points to either no address or a random address. And, variable c has an address but contains random garbage value.; c = 22; This assigns 22 to the variable c.That is, 22 is stored in the memory location of variable c.

  19. Pointer programming exercises and solutions in C

    List of pointer programming exercises. Write a C program to create, initialize and use pointers. Write a C program to add two numbers using pointers. Write a C program to swap two numbers using pointers. Write a C program to input and print array elements using pointer. Write a C program to copy one array to another using pointers.

  20. C programming exercises: Recursion

    Write a C program to check whether a given string is a palindrome or not using recursion. > Test Data : Input a word to check for palindrome : mom Expected Output: The entered word is a palindrome. Click me to see the solution. 17. Write a program in C to calculate the power of any number using recursion. > Test Data : Input the base value : 2

  21. C Arrays (With Examples)

    Access Array Elements. You can access elements of an array by indices. Suppose you declared an array mark as above. The first element is mark[0], the second element is mark[1] and so on.. Declare an Array Few keynotes:

  22. 10 Best Math AI Solvers to Solve Math Problems Online

    Simply input a question or assignment and Smodin instantly generates step-by-step solutions. The math solver AI tool consists of a simple interface that allows students to enter a question to solve. At the click of a button, the tool starts working to analyze the problem and present the best answer based on the equation.