pgd09 c++

34
PRACTICAL ASSIGNMENT OF PROGRAMMING C/C++ (PGD - 09) 2014 -2015 SUBMITTED TO SUBMITTED BY THE CHAIRPERSON TOMAL KARMAKAR

Upload: tomalk33

Post on 16-Sep-2015

269 views

Category:

Documents


15 download

DESCRIPTION

C++ Assignment

TRANSCRIPT

PRACTICAL ASSIGNMENTOFPROGRAMMING C/C++(PGD - 09)2014 -2015

SUBMITTED TO SUBMITTED BYTHE CHAIRPERSON TOMAL KARMAKARU.S.O.L PGDCAP.U. CHD.

INDEXProblem 1-------- 3Problem 2-------- 6Problem 3-------- 10Problem 4-------- 19Problem 5-------- 22Problem 6-------- 25

Problem 1Write the function oddsum() in C with function head int oddsum(int n)The function should return the sum of all odd numbers between 1 and n (including 1 and n), and you may assume that n>=1). For example, the call oddsum (7) should give the result 1+3+5+7+9+11=36.Write a main function that tests oddsum () by reading an integer from the keyboard, and if the integer is positive oddsum () should be called and the returned value is written on the screen.Solution#include#includeInt oddum(int);Void main(){ int n,sum; clrscr(); block:printf(\n Enter a number \n); scanf(%d,&n); if(n>=1){ sum=oddsum(n); printf(\n The sum of odd numbers between 1 & %d is %d.,n,sum);} else{ printf(\n Please enter a positive number); goto block;} getch();} int oddsum(int m){ int i,res; res=0; for(i=1;i