In a choice that could haunt this country for the next five years, a conservative professor, Karl Carstens, was elected today as the fifth president in post-war West Germany which is 30 years old today.

Carstens, 64, until today the speaker of the lower house of the West Germany parliament, has been a major figure on the right wing of the Christian Democratic Party for many years, enjoying a generally steady rise in his political fortunes and the respect of his conservative colleagues.

Last fall, however, as maneuvering began for the presidential nomination, Carstens' Nazi background became an issue. Begining in 1940, when he was 24, Carstens was a wartime member of the Nazi Party, as were more than 10 million other Germans.

During the post-war Allied de-Nazfication period, a West German court in Bremen ruled in August 1948 that Carstens had been only a nominal rather than a active member of the party and cleared him of serious involvement. A few weeks later, helped by U.S. judge, he was on his way to Yale University where he earned as master of law degree.

In 1949 he returned home to begin a career patterned on the model he saw in America, where professors float in and out of government service.

Because of his conservative views on both domestic and foreign policy, Carstens has long been a target of liberals and left-of-center critics. But the renewed attention to his long/forgotten party membership escalated the situation considerably, so that the new president runs a serious and widely acknowledged risk of attracting criticism by forces unfriendly to West Germany outside the country as well.

Today, the United Association of German Students announced they would sponsor demonstrations in several cities against Carstens' selection.

Real political power in West Germany rests within the chancellor's office, now occupied by Social Democrat Helmut Schmidt. The presidency is largely a nonpolitical, ceremonial office, although it has gained prestige, as Bonn's prestige, as Bonn's prestige has grown, as an important representational office internationally.It was also used in an especially effective way as a platform to critically assess the strength of the democracy here by the outgoing president, Walter Scheel.

This will be the first time, however, that rival political parties hold the presidency and the chancellor's office.

Carstens was elected today by wining a majority of 528 votes in the 1,036-member special assembly that selects the president every five years. His victory had been assured months ago when he was nominated by the joint conservative parties here.

While Schmidt's government rules in coalition with the smaller Free Democratic Party at the federal level, the conservatives rule in a majority of states and thus hold a majority in the joint federal-state assembly that elects the president.

The vote today in effect caps a bizarre episode in which many reputations were tarnished.

Public opinion polls here showed that 60 to 70 percent of West Germans wanted the extremely popular Scheel, a Free Democrat, as president again. But Scheel, knowing he could not win in the assembly, declined to be nominated. That move drew him criticism from those who felt that some conservatives might have broken ranks in the secret ballot.

After a liberal religious newspaper revived Carstens' Nazi past, the conservative newspapers, more in self-defense than in repudiation, recalled that Scheel also had been a nominal wartime party member and also had been cleared by a post-war tribunal.

So Scheel, a figure of great international prestige, was also hurt and West Germany got as president a man who was not the people's choice, according to opinion polls.

Some senior figures in the Christian Democratic Party also say privately that Carstens, because of his especially conservative views, was not the first choice of his own party leader--Helmut Kohl--or other key party figures. Yet he was not too powerful a figure to deny.

Without Scheel, Schimdt's coalition government then put on a display of political ineptness.

The Social Democrats had no candidate until the last days, when they were turned down by an aging philosopher and finally put forward the vice-president of parliament, Annemarie Renger, who received 431 voted today. The Free Democrats endorsed nobody.

Carstenss, a one-time protege of the late chancellor Konard Adenauer, served in the 1950s as Bonn's representative at the Council of Europe. Later, he was a state secretary in both the Foreign Ministry and then in the chancellory in 1967, under then-chancellor Kurt-George Kiesinger, who also was a former Nazi Party member.

Schmidt has, at times, been extremely critical of Carstens, once describing him as on the "extreme right fringe of the West German political spectrum." Schmidt, however, sensing the potential danger for West Germany, has since toned down such comments. Today, he gave Carstens a brief handshake after the vote.

The situation has focused on the a tough moral dilemma for West Germans. Carstens, like millions of others cleared after Nazi-Party-membership, pursued a career and feels he should be entitled to letting it take him as far as possible.

Carstens joined the party, he says, because as a young lawyer a judge advised him it would be a big disadvantage not to join. This has led to the charge that he was "an opportunist."

This question remains as to why, so long after the war and with so many post-war politicians around without "a past," Bonn will enter the next five years with one more potential reminder around its neck. CAPTION: Picture, West German President Karl Carstens talk with his wife, Veronica, after his election in Bonn yesterday. AP