CBS Inc. said yesterday its second-quarter earnings rose 35.9 percent from a year earlier, when its results included a $5.4 million loss from discontinued operations.

At the same time, J.P. Morgan & Co. reported earnings rose 23 percent to $2.59 a share in the second quarter from $2.11 a share in the same period of 1982, in line with others reporting so far against one of the weakest 1982 quarters for big banks.

CBS said its net second-quarter income was $58.7 million ($1.98 a share), compared with $43.2 million ($1.55), a year earlier. Income from continuing operations a year ago was $48.6 million ($1.74). Second-quarter revenue was $1.06 billion, up from $996.4 million.

In last year's second quarter, CBS discontinued a cable television programming venture and sold its Pacific Stereo chain of high-fidelity retail stores.

For the first half of this year, net income was $76.5 million ($2.58), compared with $58.9 million ($2.11). Income from continuing operations in last year's first half was $68.8 million ($2.46). Six-month revenue was $2.10 billion, up from $1.98 billion.

J.P. Morgan, whose principal subsidiary, Morgan Guaranty Trust, is the nation's fifth largest bank, said earnings were up 32 percent to $115 million in the quarter from $87.2 million in the year-ago period. The per share figure represents earnings after preferred dividends.

Morgan's gain came despite a substantial increase in loan-loss provision from last year's quarter and included a $7 million nonrecurring gain from sale of Chrysler securities it obtained in restructuring loans to the automaker.

Morgan said strong net interest earnings were the major factor in the increase that was offset, in addition to the loan-loss provision, by a more than doubling of its income taxes.

Provision for loan losses in the second quarter was $70 million, the same as for the first three months for a total of $140 million in the half, up from $34 million in the first six months of 1982.

In the first half of 1983, Morgan earned $232.8 million ($5.35), up from $173.2 million ($4.20) in the like period of 1982.

Irving Bank Corp., reported net income rose 19.7 percent in the second quarter to $2.53 a share from $2.26 a share in the year-ago period.

A decline in Irving's net interest income was offset by a rise in foreign exchange profits and fee income.

Irving's net for the quarter amounted to $23.8 million compared with $19.9 million the previous year. In the first six months, earnings increased 17.5 percent to $47.9 million ($5.05) from $40.7 million ($4.63) in the first half of 1982.

The rise in housing construction enabled Whirlpool Corp. to earn $1.12 a share in the second quarter, up from $1 a year ago as sales rose to $672 million from $637.75 million.

Net income rose to $40.68 million from $36.21 million.

First-half profit climbed to $81.2 million ($2.23) on sales of $1.275 billion from $64.38 million ($1.78) a year earlier on sales of $1.188 billion.

Chairman Jack D. Sparks said sales of kitchen ranges, dishwashers and laundry equipment were particularly brisk during the half.

Hercules Inc. reported second-quarter net income of $49.2 million ($1.04 per share), more than double the income received in the same quarter last year.

Second-quarter net income last year was $22.3 million (51 cents).

The second-quarter income this year included $47 million in profit from operations, up 57 percent from the $29.9 million in second quarter 1982 and a 44 percent improvement over the $32.6 million reported in first-quarter 1983.

First-half net income of $73.7 million ($1.58), compares with $44.2 million ($1.01) for the first half of 1982.