PGD09 C++

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

description

C++ Assignment

Transcript of PGD09 C++

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