Free Essay

C Programing

In:

Submitted By ciprim
Words 340
Pages 2
CSED 142: INTRODUCTION

TO

C PROGRAMMING & UNIX

(CSE 142) – HW #4

1. Write a C program to convert a number entered by user to its corresponding month and prints both on the screen, e.g., January for 1. If the number is outside the range of 1 to 12 print appropriate message.

int m; printf("Enter a number between 1 and 12:\n"); scanf("%d", &m); switch (m)
{
case 1: printf("January, %d\n", m); break; case 2: printf("February, %d\n", m); break; case 3: printf("March, %d\n", m); break; case 4: …

case 12: printf("December, %d\n", m); break; default: printf("please enter a number between 1 and 12.\n");
}


2. Design a multiple choice test and prompt the user to enter the correct answer and print appropriate message to let them know whether the answer was correct or not:
Which one of the following is not a type of error?
a) Syntax error
b) Debugging error
c) Runtime error
d) Logic error char c; printf("Which one of the following is not a type of error?\n\n"); printf("\ta) Syntax error\n"); printf("\tb) Debugging error\n"); printf("\tc) Runtime error\n"); printf("\td) Logic error\n"); c = getchar(); switch (c)
{
case 'a': printf("wrong!\n"); break; case 'b': printf("Correct!\n");

break; case 'c': printf("wrong!\n"); break; case 'd': printf("wrong!\n"); break; default: printf("please enter a-d.\n");
}

3.

Show that the sum of the following infinite series converges to π
(3.141592653589793).


(1) n n  0 2n  1

4

int n = 0; double sum = 0; for(n = 0; n < 1000000; n++) sum = sum + 4 * pow(-1,n)/(2*n+1); printf("sum = %lf\n", sum);

4. Taylor expansion can be used to evaluate a function. The following is the Taylor expansion of the exponential function. Write a complete program to compute an approximation to exp(0.9). n 

x

 n! n 0

#include
#include
int factorial(int n); int main(void)
{
int n; double sum = 0; for (n = 0; n

Similar Documents

Free Essay

First Programing in C#

...Programing in C# Select 7 bottons using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WFejemplo { public partial class frmboton : Form { public frmboton() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { btnprincipal.TextAlign = ContentAlignment.MiddleLeft; } private void button3_Click(object sender, EventArgs e) { btnprincipal.Enabled = true; } private void btninvisible_Click(object sender, EventArgs e) { btnprincipal.Visible = false; } private void btnvisible_Click(object sender, EventArgs e) { btnprincipal.Visible = true; } private void btnsalir_Click(object sender, EventArgs e) { Application.Exit(); } private void btndeshabilitar_Click(object sender, EventArgs e) { btnprincipal.Enabled = false; } private void btncolor_Click(object sender, EventArgs e) { btnprincipal.BackColor = Color.Chocolate; } private void btncentrar_Click(object sender, EventArgs e) { btnprincipal.TextAlign = ContentAlignment.MiddleCenter; } private void btnderecha_Click(object sender...

Words: 1167 - Pages: 5

Premium Essay

Pt1420

...the language, and b) to define a language whose implementations could be both reliable and efficient on then-available computers.” - http://pascal-central.com/ppl/#Origins In 1972 the C programming language was developed by Dennis Ritchie. C was created to work with the system Unix. “Unix gives C such advanced features as dynamic variables, multitasking, interrupt handling, forking, and strong, low-level, input-output. Because of this, C is very commonly used to program operating systems such as Unix, Windows, the MacOS, and Linux.” - http://cs.brown.edu/~adf/programming_languages.html In the 1980s the popular programming language was C++. C++ was developed at Bell Laboratories. “C++ is a general purpose multi-paradigm spanning compiled language that has both high-level and low-level languages’ features. It was started as an enhancement to the C programming language, Bjarne Stroustrup in 1979.” - http://www.freerepublic.com/focus/chat/2880277/posts In the 1990s Java was the popular programming language. It was created in 1991 developed by James Gosling at Sun Microsystems and release in 1995. In the 2000s Visual Basic (VB) was popular in the programming world. VB was developed from BASIC which was originally developed in 1964 by John Kemeny and Thomas Kurts. VB is a Microsoft programing language and software that allows programmers to create Windows based applications. VB was originally created in the early...

Words: 279 - Pages: 2

Premium Essay

Unit 1 Pt1420

...suitable for teaching programming as a systematic discipline based on fundamental concepts clearly by the language, and 2) to define a language whose implementations could be both reliable and efficient on then-available computers. In 1972 the C programming language was developed by Dennis Ritchie. C was created to work with the system Unix. “Unix gives C such advanced features as dynamic variables, multitasking, interrupt handling, forking, and strong, low-level, input-output. Because of this, C is very commonly used to program operating systems such as Unix, Windows, the MacOS, and Linux.” In the 1980s the popular programming language was C++. C++ was developed at Bell Laboratories. C++ is a general purpose multi-paradigm spanning compiled language that has both high-level and low-level languages’ features. It was started as an enhancement to the C programming language, Bjarne Stroustrup in 1979. In the 1990s Java was the popular programming language. It was created in 1991 developed by James Gosling at Sun Microsystems and release in 1995. In the 2000s Visual Basic (VB) was popular in the programming world. VB was developed from BASIC which was originally developed in 1964 by John Kemeny and Thomas Kurts. VB is a Microsoft programing language and software that allows programmers to create Windows based applications. VB was originally created in the early 1990s....

Words: 261 - Pages: 2

Premium Essay

Exploring Programming Languages

...Five popular programing languages: • 1970: o 1970 - Pascal o 1972 - C o 1972 - Smalltalk o 1972 - Prolog o 1973 - ML • 1980: o 1983 - Ada o 1983 - C++ o 1985 - Eiffel o 1987 - Perl o 1989 - FL (Backus) • 1990: o 1990 - Haskell o 1990 - Python o 1991 - Java o 1993 - Ruby o 1994 - PHP o • 2000: o ATS o Boo o C Sharp o Clojure o Cobra Who created this language? • 1970: o Niklaus Wirth o Dennis Ritchie o Alan Kay, Dan Ingalls, Adele Goldberg o Alain Colmerauer o Robin Milner • 1980: o Jean Ichbiah o Bjarne Stroustrup o Bertrand Meyer o Larry Wall o John Backus, John Williams, Edward Wimmers • 1990: o Simon Peyton Jones, Lennart Augustsson, Dave Barton, Brian Boutel, Warren Burton, Joseph Fasel, Kevin Hammond, Ralf Hinze, Paul Hudak, John Hughes, Thomas Johnsson, Mark Jones, John Launchbury, Erik Meijer, John Peterson, Alastair Reid, Colin Runciman, Philip Wadler o Guido van Rossum o James Gosling and Sun Microsystems o Yukihiro Matsumoto o Rasmus Lerdorf • 2000: o Hongwei Xi o Rodrigo B. De Oliveira o Microsoft o Rich Hickey o Charles Esterbrook When was each of these languages created? Was there a specific motivation behind the creation of these languages? If so, what was it? • 1970: o 1970 – Yes, intended to teach students structured programming o 1972 – Yes, designed to be compiled using a relatively straightforward compiler, to provide low-level access to memory, to provide language...

Words: 423 - Pages: 2

Premium Essay

Student

...1970’s SQL (structured query language): create in 1970, developed by IBM, reason was as a language to query relational databases. Retrieved from http://internationalprogrammersday.org/the-history-of-programming-languages/ Pascal: created in 1970, developed by Niklaus Writh, created to be a structured programing languages (has similarities with C). Retrieved from http://internationalprogrammersday.org/the-history-of-programming-languages/ C: created in 1973, developed at AT&T bell labs programmer Dennis Ritchie. It was intended for the Unix operating system but quickly spread due to its portability and speed. Retrieved from http://internationalprogrammersday.org/the-history-of-programming-languages/ AWK (named after creators initials): created in 1974, developed by Aho Kerninghan Weinberger, Word processing language based on regular expressions, using a pattern-action principle. Retrieved from http://www.scriptol.com/programming/history.php Applesoft Basic: created in 1977, developed by Microsoft for the Apple ll computer. It was an extension of the Basic language. Retrieved from http://internationalprogrammersday.org/the-history-of-programming-languages/ 1980’s BASICA: created in 1981, developed by Microsoft for MS-DOS. Retrieved from http://internationalprogrammersday.org/the-history-of-programming-languages/ Turbo Pascal: created in 1983, developed by Anders Hejisberg, it was an extension of pascal and it came bund led with a full IDE (it was a great improvement...

Words: 981 - Pages: 4

Free Essay

Synopsis

...Term-paper Synopsis Registration Number: 11114018 Names(s) of Student: Mukesh kumar Roll no. RD1105A41 Term Paper on WHY WE USE POINTERS ? ADVANTAGES AND DISADVANTAGE OF USING POINTER S AND ITS aPPLICATION | | | | | | | | | | | Estimated duration: 1 week Nature of Paper : TECHNICAL Paper Description: In this topic we discuss all about Pointer With their Uses related to program,advantage,disadvantage,and it’s application. Here we discuss some reasons why we use Pointer:- What is a pointer? Pointer is nothing , it is just a variable which hold the Address of another variable. For example, consider the variable declaration: int *ptr; ptr is the name of our variable. The '*' informs the compiler that we want a pointer variable. The int says that we intend to use our pointer variable to store the address of an integer . Such a pointer is said to "point to" an integer. Why Have Pointers? Pointers solve two common software problems. First, pointers allow different sections of code to share information...

Words: 560 - Pages: 3

Premium Essay

Essay

...STATE ENGINEERING UNIVERCITY OF ARMENIA (Politechnik) Report Theme: A history of computer programming languages Student: Davtyan Maria Professor: Ghazaryan Hasmik Group: ՄՏՏ 304 Yerevan 2014 A History of Computer Programming Languages Ever since the invention of Charles Babbage’s difference engine in 1822, computers have required a means of instructing them to perform a specific task. This means is known as a programming language. Computer languages were first composed of a series of steps to wire a particular program; these morphed into a series of steps keyed into the computer and then executed; later these languages acquired advanced features such as logical branching and object orientation. The computer languages of the last fifty years have come in two stages, the first major languages and the second major languages, which are in use today. In the beginning, Charles Babbage’s difference engine could only be made to execute tasks by changing the gears which executed the calculations. Thus, the earliest form of a computer language was physical motion. Eventually, physical motion was replaced by electrical signals when the US Government built the ENIAC in 1942. It followed many of the same principles of Babbage’s engine and hence, could only be “programmed” by presetting switches and rewiring the entire system for each new “program” or calculation. This...

Words: 2186 - Pages: 9

Premium Essay

Bout This

...*Structures Of a Java Programming * Result Of Executing The Java Programing Object Oriented Programming Language (OOPL) OOPL Is An Extension Of Procedural Language. Involves Creating Program Components as Object Related To The Real Word. Writing Object-Oriented Programs Involves Creating Object And Application That Uses Those Objects. An Object Contains Both Data Procedures Can be packaged Into a Single Unit. Based On Three Concepts Encapsulation Ability To Bind Data And Procedures Into an Object. Inheritance Ability Of Objects To Acquire The Attributes Or Behavior Of Other Objects Or Classes. Polymorphism Ability of An Object To Take Many Forms Or Identities. Benefits Of Object-Oriented Programming *Reusability -Able To Reuse The Defined Objects. *Adaptability –Able to fit in different environment. *maintainability –Able to change easily. *reliability –Able to operate correctlyunder all conditions. Intro Java *Java developed by James gosling at sun Microsystem in 1991. *Introduced in 1995 (version 1) *The language was first called “Oak”. *An object oriented programming language (OOPL). *Suitable for business application and the world wide web (www) application Based on C++. Platform independent –Able to...

Words: 1445 - Pages: 6

Premium Essay

Saylor

...[Note: This document has been modified from the original by the Saylor Foundation] Introduction to Software History by Cornelis Robat, Editor First Steps This part will be different from the History of the computer, no chronological travel through software-land, but a collection of articles and assays on software. Software has a long history and as far as the facts are known to us we will give them to you. When missing stories, data, or other information are shared to us they will be put on this site. If you have any comments of suggestions regarding this page or any other page please do not hesitate to contact us. A simple question: "What is software?" A very simple answer is: Hardware you can touch, software you can't. But that is too simple indeed. Source URL: http://www.thocp.net/software/software_reference/introduction_to_software_history.htm Saylor URL: http://www.saylor.org/courses/cs101/ Attributed to: The History of Computing Project www.saylor.org Page 1 of 23 But when talking about software you talk about programming and programming languages. But about producing and selling the products made by programming (languages) as well. There are over 300 different ("common") computer languages in existence, apart from the various dialects stemming from one of them. Most of them can be classified in definable groups, but others don’t belong to anything. Some because they are rather new or the use of them was or is never wide spread and only used by a small specialized...

Words: 5456 - Pages: 22

Free Essay

It/218 Object Oriented Programming

...Object oriented programming refers to a method of programming in which individual objects, usually called "methods" and "functions", are created and used in junction with each other to perform a function. These objects are organized within the program through use of things called structures or classes. A class is something we use to create a blueprint of sorts for a assortment of variables and components. Similarly, a structure serves the same purpose. The only difference between a structure and a class is that a structure's members are public by default and a classes members are private by default. Another form of "blueprint" used by programmers is the data union. While a union is very primitive in comparison to a structure or class, it is a good tool to use to conserve memory in larger applications. A union uses the same memory block for multiple variables at different points. While two variables in a union cannot be accessed at the same time, a union is a good way to re-use blocks of memory that would normally be left void after a variable is finished with. Now that I have covered the basic points of classes, structures and unions, I will go into more detail of just how powerful a class or structure can be. In basic reference, a class is simply a blueprint to something we create instances of later in the program. This is a very vague statement however, because in object-oriented programming the class is the backbone of the program. It is what makes the...

Words: 813 - Pages: 4

Premium Essay

Private Fitness Inc. Case

...To: Rosemary Worth From: Re: misplaced trust on Kate Hoffman causing money loss issue Date: September 17, 2012 This memo is in response to your questions concerning money loss issue raised by Kate Hoffman and any related operating problems. After an in depth study of your company’s daily operation procedure and a situation that you are unable to step in a managerial role because of family responsibilities, I suggest you hire a new manager to take care of daily operation management, focus on 3-4 popular classes, shorten opening hours, and base commissions on performance. My suggestion is based on obtaining better management controls in the following three aspects. People Controls You trust Kate Hoffman so much that you let her take multiple tasks such as marketing, facility up-keeping, scheduling of appointments and record keeping. Kate was paid a salary plus a commission based on gross revenues just as other instructors. Kate might have thought that she did more work than other instructors and deserved more commission. When her expectation was not met, she lacked the motivation to handle multiple tasks and turned to an unethical way – stealing money from unrecorded revenue. If a new manager is hired, Kate can be released from administrative work and concentrate on her instructor job. Thus, further money loss can be avoided, and you can still keep the friendship between Kate and you as before. Furthermore, the newly hired manager can take place of the part time clerical...

Words: 910 - Pages: 4

Free Essay

Clothing

...Lab # 4 OVERLOADING Coding : using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 {//*********************************multiplication************************************ class A { public int multiply(int a,int b) { return a * b; } public double multiply(int a, double b) { return a * b; } public double multiply(double a, double b) { //1 argument type different OVERLOADING can be performed return a * b; } }//*********************************fraction************************************ #region fraction class fraction { int numerator, denominator; //field public void display() { Console.WriteLine(numerator + "/" + denominator); } public fraction() { numerator = 0; denominator = 1; } public fraction( int n, int d) { numerator = n; denominator = d; } public fraction(int n) { numerator = n; denominator = 1; } } #endregion //*********************************length************************************ #region length class length { int feet, inches; public void display() { ...

Words: 276 - Pages: 2

Premium Essay

Intro to Programming Unit 1 Research Assignment

...structured programming and data structuring. 2) SQL (Structured Query Language) designed by, Donald D. Chamberlin, and Raymond F. Boyce. The motivation behind this language was designed for managing data held in a relational database management system. ( RDBMS) 3) C, Designed by Dennis Ritchie. the motivation behind this language is structured programming and allows lexical variable scope and recursion. 4) Applesoft BASIC, developed by Marc McDonald, and Ric Weiland. The motivation with this language was it was designed to be backwards-compatible with integer BASIC and used the core of Microsoft’s 6502 BASIC implementation. 5) GRASS, Developed by Thomas A. DeFanti. GRASS is similar to BASIC in sytax, but added numerous instructions for specifying 2D object animation, including scaling, translation, rotation and color changes over time. 1980’s 1) BASICA, Designed by Thomas E. Kurtz. Designed to offer support for the graphics and sound hardware of the IBM PC line. 2) Turbo Pascal, developed by Borland, under Philippe Kahn’s leadership. This is a software development system that includes a compiler and an integrated development environment for the Pascal programming language. 3) C++, designed by Bjarne Stroustrup. This is a general purpose programming language that is free-form and compiled. It is regarded as an intermediate-level language, as it comprises both high-level and low-level language features. It provides imperative, object-oriented and...

Words: 677 - Pages: 3

Premium Essay

Reusability of Code

...Reusability of Code To be able to compare and contrast procedural programming modules and object-oriented programming, or OOP for short, we need to understand the two different styles. Procedural programming was the most commonly used programming language early on with a top-down model. This programming module places its attention on procedures or actions, which take place within the program. A few examples of procedural programming are FORTRAN and BASIC. OOP although has become the preferred method of use. OOP focuses on objects, which are self-contained unit containing date and data operations. When it comes to the reusability of codes OOP makes this task much easier. As procedural programming is a line-by-line programming style as if to be writing out simple instructions. OOP however allows the programmer to utilize inheritance. Inheritance gives the programmer the ability to create new classes, known as subclasses, based on an existing class, known as the superclass. This ability enables the programmer to utilize the data and methods of the original class or superclass. This whole process is where the programmer is able to utilize code that already was written saving them time and eliminating the opportunity for programming errors. Another benefit to OOP over procedural programming is security and the ability to hide code. Within OOP, the programmer is able to label certain data fields as private. Once these data fields are labeled as private, their data and methods...

Words: 621 - Pages: 3

Premium Essay

Let Us C - Yashwant Kanetkar.Pdf

...Let Us C Fifth Edition Yashavant P. Kanetkar Dedicated to baba Who couldn’t be here to see this day... About the Author Destiny drew Yashavant Kanetkar towards computers when the IT industry was just making a beginning in India. Having completed his education from VJTI Mumbai and IIT Kanpur in Mechanical Engineering he started his training company in Nagpur. Yashavant has a passion for writing and is an author of several books in C, C++, VC++, C#, .NET, DirectX and COM programming. He is a much sought after speaker on various technology subjects and is a regular columnist for Express Computers and Developer 2.0. His current affiliations include being a Director of KICIT, a training company and DCube Software Technologies, a software development company. In recognition to his contribution Microsoft awarded him the prestigious “Best .NET Technical Contributor” award recently. He can be reached at kanetkar@kicit.com. Preface to the Fifth Edition It is mid 2004. World has left behind the DOTCOM bust, 9/11 tragedy, the economic downturn, etc. and moved on. Countless Indians have relentlessly worked for close to two decades to successfully establish “India” as a software brand. At times I take secret pleasure in seeing that a book that I have been part of, has contributed in its own little way in shaping so many budding careers that have made the “India” brand acceptable. Computing and the way people use C for doing it keeps changing as years go by. So overwhelming...

Words: 46379 - Pages: 186