President Carter easily won the Illinois primary tonight, rolling up lopsided margins over Sen. Edward M. Kennedy among virtually every segment of this state's diverse electorate.

The president's victory in the non-binding presidential preference primary was a crippling blow to the Massachusetts senator's rapidly diminishing hopes of remaining a credible candidate in the Democratic presidential race.

With 79 percent of the vote counted, Carter led Kennedy 65 percent to 30 percent. California Gov. Edmund G. (Jerry) Brown Jr., who was on the ballot but did not campaign here, was getting 3 percent of the vote.

A Washington Post poll of voters at randomly selected precincts around the state projected the president's final margin at about 2 to 1.

There were only scattered returns tonight from the separate voting to select Illinois' delegates to the Democratic National Convention in August. Delegates pledged to Kennedy and Carter were elected from each of the state's 24 congressional districts, and Carter aides here predicted that the president would come out far ahead in these contests as well, when all the votes are counted.

"It's spectacular," Jim Johnson, executive assistant to Vice President Mondale, said tonight. Johnson predicted that Carter would win "substantially more than a majority" of the delegates even in Chicago, the strong-hold of Kennedy's principal Illinois allies.

The president was expected virtually to sweep the delegate races elsewhere in Illinois and to end up with most of the 152 delegates at stake statewide.

Kennedy's chance of winning delegates appeared tonight to be largely confined to two of the seven congressional districts within Chicago where the local Democratic organization is strongest, according to Carter campaign officials.

Kennedy had pinned his hopes on winning a large share of the 49 delegates from the city on the strength of his support from Mayor Jane Byrne and the Cook County Democratic organization.

Kennedy appeared before reporters in New York late tonight and gave no indication of backing down from his vow to remain in the race until the Democratic convention.

"It would be unfortunate indeed if the success of the administration in Illinois would be interpreted as a referendum on economic policies or foreign policies of the administration," he said.

Kennedy said next Tuesday's New York primary will be such a referendum, and that it is essential for him to do well in New York.

Asked what he will do if he does not do well in New York, Kennedy replied: "I will continue."

In response to questions, he did not explain why New York qualified as a referendum on Carter's record and Illinois did not.

Tonight, Kennedy's Illinois campaign chairman, Rep. Paul Simon (D-Ill.), tried to put the best face on the senator's decisive defeat in a state once thought to be one of his strongholds.

"We were hoping for roughly one-third of the vote or one-third of the delegates," Simon said. "It's a long way from over in the campaign."

Adopting the line that Kennedy has taken in the face of a string of defeats, Simon said the campaign "could turn around next week in the New York primary, or two weeks, three weeks, four weeks from now. He can keep going for a long time."

The Carter campaign's national chairman, Robert S. Strauss, predicted that the president and Kennedy would about split the 282 New York delegates in next week's primary. He argued that "a wash in the delegates is a win for us" because Kennedy is now so far behind in the number of delegates won.

Strauss also said he was encouraged by Carter's showing here among black and Jewish voters, two important elements in the New York primary. He said the president defeated Kennedy by about a 3-to-2 ratio in Skokie, a suburb north of Chicago and the most heavily Jewish area of the state.

Besides Kennedy, the big loser tonight was Byrne. She was one of Kennedy's earliest supporters and had predicted that she would deliver all of the city's delegates to the Massachusetts senator.

Her top priority in local races was the defeat of state Sen. Richard M. Daley -- a likely opponent of Byrne in the 1983 mayoral election -- by Alderman Edward Burke in the race for Cook County state's attorney. Daley, oldest son of Chicago's late mayor, Richard J. Daley, swamped Burke as badly as Carter defeated Kennedy.

But in a stunning flight from the reality of the Illinois results, Byrne declared tonight, "I didn't lose," because the vast majority of organization-backed candidates in dozens of other local races won.

Byrne said she hoped that Kennedy does not drop out of the race, and sidestepped questions on whether she will support the president in November if he is the Democratic nominee.

The Post's poll indicated that Carter's victory was broadly based throughout the state and among the various elements of the Illinois electorate. Kennedy carried the 8 percent of the voters who consider themselves liberal or very liberal, but even among them his margin was fairly narrow.

Carter carried white voters by 2 to 1 and blacks by almost that much. He won the Protestant vote by a 2-to-1 ratio and was the choice of Catholic voters by 58 to 38 percent.

Kennedy enjoyed labor union support in this heavily unionized state, but even that did not help him. According to The Post's poll, the president won the votes of both union and nonunion families by 2 to 1.

Overall, The Post poll indicated that Carter still enjoys the approval of a majority of voters, with negative voting patterns aimed at Kennedy or Brown accounting for about one-fourth of the president's support.

The poll also suggested that Kennedy failed to make inroads here on the key issue of inflation, which he has been stressing in his campaign.

The Massachusetts senator won a narrow majority among voters who said they have been seriously hurt by inflation. But among other voters, including those who expect to be hurt soon by rising prices, Carter ran strongly.

Three-fourths of the Carter voters said they do not believe there is much any president can do to control inflation.

An analysis of voting patterns by ABC News also demonstrated the breadth of the Carter win among traditional Democratic constituent groups. The president, according to ABC, ran as well in urban areas as he did in the suburbs. Kennedy's strongest showing was among low-income voters, but even among them he failed to win a majority.

When Kennedy announced his candidacy last fall, both he and the president said that Illinois, because of its size, location and place in the political calendar, would provide a crucial test in the Democratic presidential race.

The 152 convention delegates elected here today form the largest convention bloc chosen so far this year, in the first large, industrial state that was considered politically neutral ground -- outside Kennedy's home region of New England or Carter's native South.

Illinois will send 179 delegates to the August Democratic National convention in New York. The additional delegates will be chosen next month in a state convention.

Early in the campaign, Kennedy aides viewed Illinois as the place where the Massachusetts senator might eliminate the president from the race. But that was before the Iran and Afghanistan crises, Carter's rise in popularity, and the president's string of victories over Kennedy in every contest leading up to the Illinois showdown except Kennedy's homestate primary in Massachusetts.

As a result, the Kennedy campaign here found itself with a poorly organized and under-financed effort, shackled with the support of Chicago's increasingly unpopular mayor, and reduced to reliance on the city's declining political machine to win a majority of the 49 convention delegates elected from congressional districts within Chicago.

Byrne was a key factor. Her support was assiduously courted by both Carter and Kennedy, and her abrupt reversal last fall -- from a near endorsement of the president to all-out support for Kennedy within a matter of days -- appeared to rankle Chicago voters and exacerbate Kennedy's problems.

But Byrne did provide the support of the city's ward committeemen and hundreds of precinct workers, who were considered vital to the election of Kennedy delegates, even if the senator lost the popularity contest.

Kennedy was also plagued here, more so than elsewhere, according to his aides, by questions about Chappaquiddick and his lifestyle. Local politicians said they found remarkably high levels of resistance to Kennedy because of this in Chicago's heavily ethnic Catholic neighborhoods, which at one point were considered likely strongholds for the youngest brother of the county's first Roman Catholic president, John F. Kennedy.

"We were never able to crack through that," said one Kennedy aide before the election.

The Carter campaign, aware of Kennedy's problems over lifestyle and Chappaquiddick, stressed the president's devotion to home and family in it's advertising.

Negative feelings toward Kennedy were also cited to explain why the senator appeared to benefit so little from an erosion in Carter's support. Newspaper polls before the primary showed the president's popularity declining, but Kennedy's was not rising.

In his final week of campaigning here, Kennedy concentrated on Chicago's ethnic neighborhoods, strongholds of the local Democratic organization, where he stood the best chance of winning convention delegates. He reiterated his call for wage and price controls and an overall economic freeze, and called the president's latest anti-inflation proposals "too little, too late and too unfair."

He also courted the Chicago area's large Jewish vote by denouncing the administration's blunder over the U.N. resolution censuring Israel's settlements policy.

But the Kennedy campaign was shadowed by misfortune. During a campaign appearance here Friday, Kennedy was informed that his close friend and supporter, former New York congressman Allard Lowenstein, had been shot while in his New York City office. Kennedy flew to New York that night, arriving after Lowenstein had died.

In concentrating on Chicago, Kennedy conceded beforehand that Carter would win both the popular vote and the bulk of the convention delegates elected in downstate districts. However, he hoped to pick off some of those delegates by relying on some of the popular and well-known Illinois political figures who headed his delegate slates in those areas.

The president's campaign conducted by Vice President Mondale and other surrogates, was largely an exercise in educating voters to the complexities of the Illinois ballot and the need to vote in both the "beauty contest" preference primary and the delegate selection process.

Confident of winning the popularity contest, Carter aides privately also hoped to chalk up a healthy majority of delegates, including several from Chicago.

Their chief concern was the possibility of a heavy Democratic crossover vote in the Republican primary to support GOP hopeful John Anderson. Particularly in the Chicago suburbs, considered a Carter stronghold, Anderson crossover votes could have hurt the president, Carter aides said.