Preview from Notesale.co.uk Page 4 of 63

Similar documents
'C' Programming Language

/* Area and circumference of a circle */ /*celsius to fahrenheit*/

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE

Branching is deciding what actions to take and Looping is deciding how many times to take a certain action.

Two Dimensional Array - An array with a multiple indexs.

Subject: PIC Chapter 2.

Decision Making and Branching

WAP 10. WAP 11. WAP 12. WAP 13. WAP 14. WAP 15. WAP 16. WAP 1. : 17. WAP 18. WAP 19. WAP 20. WAP 21. WAP 22. WAP 23. WAP & 24. WAP

MA 511: Computer Programming Lecture 2: Partha Sarathi Mandal

Introduction to Computing Lecture 07: Repetition and Loop Statements (Part II)

ME 172. C Programming Language Sessional Lecture 8

UIC. C Programming Primer. Bharathidasan University

Answer for I/O Operation Exercise:

Functions. (transfer of parameters, returned values, recursion, function pointers).

Structured programming

PROGRAMMING IN C AND C++:

The Hyderabad Public School, Begumpet, Hyderabad, A.P

Fundamentals of Programming Session 14

Worksheet 4 Basic Input functions and Mathematical Operators

Two Dimensional Array - An array with a multiple indexs.

C Programming Lecture V

Engineering 12 - Spring, 1999

4(a) ADDITION OF TWO NUMBERS. Program:

Structured programming

Engineering 12 - Spring, 2000

Programming and Data Structures

x 2 +7x+1 x<0 7x+17 0<x 10 Z= x 2 +10x x 25 25x+100 other values

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

1) Write a C Program to check whether given year is Leap year or not. AIM: A C Program to check whether given year is Leap year or not.

Unit 5. Decision Making and Looping. School of Science and Technology INTRODUCTION

Engineering 12 - Spring, 1998

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS)

Solutions to Assessment

Lab Session # 1 Introduction to C Language. ALQUDS University Department of Computer Engineering

BCSE1002: Computer Programming and Problem Solving LAB MANUAL

Slides adopted from T. Ferguson Spring 2016

Lecture 3. Variables. Variables

LOOPS. 1- Write a program that prompts user to enter an integer N and determines and prints the sum of cubes from 5 to N (i.e. sum of 5 3 to N 3 ).

Lecture 6. Statements

UNIT III ARRAYS AND STRINGS

only in the space provided. Do the rough work in the space provided for it. The question paper has total 12 pages.

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities

PESIT Bangalore South Campus Hosur Road (1km before Electronic City), Bengaluru Department of Basic Science and Humanities

Multiple Choice Questions ( 1 mark)

***************OUTPUT*************************** Enter the two number The addition of two number is =100

1. Basics 1. Write a program to add any two-given integer. Algorithm Code 2. Write a program to calculate the volume of a given sphere Formula Code

Government Polytechnic Muzaffarpur.

F28HS2 Hardware-Software Interface. Lecture 1: Programming in C 1

Chapter 3 Problem Solving and the Computer

2008/11/05: Lecture 15 CMSC 104, Section 0101 John Y. Park

SUMMER 13 EXAMINATION Model Answer

I YEAR II SEMESTER COMPUTER SCIENCE PROGRAMMING IN C

Note: If only one statement is to be followed by the if or else condition then there is no need of parenthesis.

Syntax of for loop is as follows: for (inite; terme; updatee) { block of statements executed if terme is true;

Fundamentals of Programming Session 15

SRI VIDYA COLLEGE OF ENGINEERING & TECHNOLOGY, VIRUDHUNAGAR Department of CSE & IT Internal Test I

Fundamental of Programming (C)

LAB 5: REPETITION STRUCTURE(LOOP)

LAB 6: While and do-while Loops

More examples for Control statements

Functions. Arash Rafiey. September 26, 2017

Dalhousie University CSCI 2132 Software Development Winter 2018 Midterm Examination II March 12 15:37-16:24

16.216: ECE Application Programming Fall 2011

Programming Language A

Module 6: Array in C

Computer Programming Unit 3

Procedural Programming

Ex. No. 3 C PROGRAMMING

UNDERSTANDING THE COMPUTER S MEMORY

LAB 5: REPETITION STRUCTURE(LOOP)

SHARDAYATAN -E.M STD-10 C-PROGRAMS

Scheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C

Computer Programing. for Physicists [SCPY204] Class 02: 25 Jan 2018

H192 Midterm 1 Review. Tom Zajdel

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

CSE101-Lec#18. Multidimensional Arrays Application of arrays. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming

VARIABLE, OPERATOR AND EXPRESSION [SET 1]

Basic Assignment and Arithmetic Operators

CSE123 LECTURE 3-1. Program Design and Control Structures Repetitions (Loops) 1-1

Fundamentals of Programming

Use a calculator and c = 2 π r to calculate the circumference of a circle with a radius of 1.0.

Iosif Ignat, Marius Joldoș Laboratory Guide 4. Statements. STATEMENTS in C

Computer Programming. Decision Making (2) Loops

I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each.

C PROGRAMMING LAB MANUAL

Precedence and Associativity Table. % specifiers in ANSI C: String Control Codes:

What we have learned so far

Ryerson University Vers HAL6891A-05 School of Computer Science CPS109 Midterm Test Fall 05 page 1 of 6

Assignment 6. Q1. Create a database of students using structures, where in each entry of the database will have the following fields:

Programming & Data Structure Laboratory. Day 2, July 24, 2014

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

Module 4: Decision-making and forming loops

Loops / Repetition Statements

!"#$% &'($) *+!$ 0!'" 0+'&"$.&0-2$ 10.+3&2),&/3+, %&&/3+, C,-"!.&/+"*0.&('1 :2 %*10% *%7)/ 30'&. 0% /4%./

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

PESIT Bangalore South Campus Hosur road, 1km before ElectronicCity, Bengaluru -100 Department of Basic Science and Humanities

Procedural Programming

// CSE/CE/IT 124 JULY 2015, 2.a. algorithm to inverse the digits of a given integer. Step 1: Start Step 2: Read: NUMBER Step 3: r=0,rev=0

Subject: Fundamental of Computer Programming 2068

Tribhuvan University Institute of Science and Technology 2065

Transcription:

1. Write a program to compute area of a circle after reading input from user. #include <stdio.h> #include <conio.h> int float area, radius, pi=3.141; printf("enter the radius of circle \t"); scanf("%f", &radius); printf("area of a circle is %f", area=pi*radius*radius); 2. Write a program to calculate total marks. int n, a, b, c=0; printf("\n\nwrite the number of subjects\t"); scanf("%i", &n); for(int a=0;a<n;a++) printf("enter the marks of subject\t"); scanf("%i", &b); c=c+b; printf("\n\n\t\ttotal MARKS ARE %i", c); Page 4 of 63 3. Write a program to calculate total marks and percentage of three subjects. #include <stdio.h> #include <conio.h> int float a, b, c ; printf("enter the marks of first subject \t"); scanf("%f", &a); printf("enter the marks of second subject \t"); 4 P a g e

scanf("%f", &b); printf("enter the marks of third subject \t"); scanf("%f", &c); printf("total marks of subject are\t\t %f \n", a+b+c); printf("percentage of total marks is \t %f", (a+b+c)/300*100); 4. Write a program to find out power of any number. int num, pow, a=1, i; printf("enter the number\t"); scanf("%d", &num); printf("\nenter its power\t\t"); scanf("%d", &pow); for(i=1;i<=pow;i++) a=a*num; Page 5 of 63 printf("\n\n\t\t%d^%d is %d", num, pow, a); getche(); 5. Write a program to Sum, Subtract, Multiply and Division of two numbers. #include <stdio.h> #include <conio.h> int float a, b ; printf("enter the marks of first number \t"); scanf("%f", &a); printf("enter the marks of second number \t"); scanf("%f", &b); 5 P a g e

if(a==e && b==d) printf(a==e && b==d? "\n\noriginal and reversed numbers are equal":"\n\noriginal and reversed numbers are not equal"); if(a!=e && b!=d) printf("\n\noriginal and reversed numbers are not equal"); 18. Any year is input through the keyboard. Write a program to determine whether the year is a leap year or not. int year; printf("enter a Year\t"); scanf("%d",&year); if(year%100==0) if(year%400==0) printf("\nit is a Leap Year"); printf("\nit is not Leap Year"); if(year%4==0) printf("\nit is a Leap Year"); printf("\nit is not Leap Year"); 19. Write a program using conditional operators to determine whether a year entered through the keyboard is a leap year or not. Page 16 of 63 16 P a g e

int a, b, c; printf("enter first angle of triangle\t"); scanf("%d",&a); printf("enter second angle of triangle\t"); scanf("%d",&b); printf("enter third angle of triangle\t"); scanf("%d",&c); if(a+b+c==180) printf("\ntriangle is valid"); printf("\ntriangle is not valid"); 22. Find the absolute value of a number entered through the keyboard. int num; printf("enter a number to find its absolute value\t"); scanf("%d",&num); Page 18 of 63 if(num<0) num=(-1)*num; printf("\nabsolute value of number is %d", num); 23. Write a program to find the greatest of the three numbers entered through the keyboard using conditional operators. int a, b, c; printf("enter first number\t"); 18 P a g e

printf( "\n\tarea of triangle is\t%f", area= s*(s-a)*(s-b)*(s-c) ); printf("triangle is not valid"); 26. Write a program that inputs an integer determine if it is even or odd. main( ) int num; printf( "Enter the number\t" ) ; scanf("%d", &num); if(num%2==0) printf( "\n\tnumber you enter is even"); printf("\n\tnumber is odd"); 27. Write a program that determines the number entered by the user is even or odd. After displaying the message ( Even or Odd ), it ask the user Do you want to enter another number (y/n). If the user enter y, it do the same process again otherwise exit. (Note: use dowhile loop) main( ) int x; char y; do Page 20 of 63 printf( "\n\nenter the number\t" ) ; scanf("%d", &x); 20 P a g e

printf("enter number\t"); scanf("%f", &d); printf("\nthe sum of series is\t%f", d); printf("\nmean of series is\t%f", d); printf("\nthe maximum number is\t%f", d); printf("\nthe minimum number is\t%f", d); printf("\nenter 1st numbers in series\t"); scanf("%f", &d); while(i<a) printf("enter the other numbers in series\t"); scanf("%f", &f); if(f>d) g=f; if(f>d) h=d; s=s+f; Page 32 of 63 count++; i++; s=s+d; m=s/count; printf("\nthe sum of series is\t%f", s); printf("\nmean of series is\t%f", m); printf("\nthe maximum number is\t%f", g); printf("\nthe minimum number is\t%f", h); 32 P a g e

scanf("%d%d",&n,&p); y=power(n,p); printf("%d^%d=%d",n,p,y); int power(int a, int s) int pow=1; for(int i=1;i<=s;i++) pow=pow*a; return pow; b. by recursion method #include<stdlib.h> int power(int,int ); int int n,p,result; printf("enter base number: "); scanf("%d",&n); printf("enter power number: "); scanf("%d",&p); result=power(n,p); printf("%d^%d=%d",n,p,result); int power(int a,int s) if(s==1) return a; Page 37 of 63 37 P a g e

55. Write a program that reads any number (ask user) of integers from a user, and then prints total number of even, and odd integers entered. The program also prints the total number of zeros. printf("some instructions:\n"); printf("it read also '0' as even including those divisible by 2 and "); printf("1 as odd number and it will not count starting zeros of a number"); printf("\nmeans for'0090' it will count only one zero"); int a, e=0, o=0, z=0, k; printf("\nenter the number\t"); scanf("%d", &a); for(;a!=0;) k=a%10; a/=10; if(k%2==0&&k!=1) e++; if(k%2==1 k==1) o++; if(k==0) z++; printf("\n\n3total number of even integers are %d",e); printf("\ntotal number of odd are integers %d",o); printf("\ntotal number of zeros are integers %d",z); Page 49 of 63 49 P a g e

56. Ten different numbers are input in an array. Write a program to search a specific value in the array. If array contain that value then add that value in all elements of the array. int array[10]; printf("enter the 10 values you want to put in an array\n"); for(int i=0;i<10;i++) scanf("%d", &array[i]); int num; printf("enter the number to search in array\n"); scanf("%d", &num); int check; for(int i=0;i<10;i++)if(num==array[i])check=1;break; check=0; if (check==1)for(int i=0;i<10;i++)array[i]=array[i]+num; printf("array is"); for(int i=0;i<10;i++)printf(" %d",array[i]); Page 50 of 63 57. Forty students were asked to rate the quality of food in the student cafeteria, on a scale of 1 to 10 (1 means awful and 10 means excellent). Place the forty responses in an integer array and summarize the results of the poll. #include <stdio.h> #include <conio.h> void func(int responses[]) int answe, ratin, frequenc[ 11 ] = 0 ; for ( answe = 0; answe < 40 ; answe++ ) ++frequenc[ responses [ answe ] ]; for ( ratin = 1; ratin <= 10; ratin++ ) 50 P a g e

int printf( "\n%d \t%d\n", ratin, frequenc[ ratin ] ); int response[ 40 ] = 5, 8, 3, 5, 5, 9, 10, 8, 5, 7,1, 2, 5, 4, 4, 5, 5, 6, 3, 2,1, 1, 3, 3, 4, 1, 3, 4, 2, 4,5, 5, 10, 3, 3, 6, 7, 5, 4, 4,; printf( "Item quality POLL\n" ); printf( "%s\t%s\n", "Rating", "Frequency" ); func(response); printf( "\n\n" ); 58. Write a program which performs the following tasks: initialize an integer array of 10 elements in main( ) pass the entire array to a function modify( ) in modify( ) multiply each element of array by 3 return the control to main( ) and print the new array elements in main( ) void modify(int arr[]) modify(array); for(int i=0;i<10;i++) arr[i]=arr[i]*3; int array[10]=1,2,32,3,43,2,1,4,5,6; for(int i=0;i<10;i++) printf(" %d", array[i]); Page 51 of 63 51 P a g e