Professional Documents
Culture Documents
1 10 100 1000
2 20 200 2000
9 90 900 9000
#include <iostream>
int main() {
int n;
cin>>n;
cout<<j<<"\t";
cout<<endl;
return 0;
2. Write a program to enter a number and show how many times a digit appeared in number
e.g., n = 23531
1 =1 times
2 = 1 times
3= 2 times
5 = 1 times
#include <iostream>
using namespace std;
int main() {
int n,r,d,count;
cin>>n;
int mpos=1;
for(int i=n; i>0; i=i/10){
r=i%10;
int spos=1;
count=0;
for(int j=n; j>0; j=j/10){
d=j%10;
if(r==d){
if(spos<mpos)
break;
count++;
}
spos++;
}
if(count>0){
cout<<r<<" occurs "<<count<<" times "<<endl;
}
mpos++;
}
return 0;
}
3. Write a program to enter an expression and display its result whne = is pressed/
#include <iostream>
#include <conio.h>
int main() {
for(;;){
ch=getche();
n2=n2*10+ch-48;
else{
if(flag=='f'){
n1=n2;
op=ch;
n2=0;
flag='t';
continue;
switch(op){
case '+':
n1=n1+n2;
break;
case '-':
n1=n1-n2;
break;
case '*':
n1=n1*n2;
break;
case '/':
n1=n1/n2;
break;
default:
cout<<"Invalid operator";
n2=0;
op=ch;
if(ch=='='){
break;
cout<<n1;
return 0;
n! / k! (n – k )!
5.
#include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
for(int i=1; i<=n; i++){
char ch=65;
for(int j=1; j<=n*2-1; j++){
if(j>=n-i+2 && j<=n+i-2){
cout<<" ";
}
else{
cout<<ch;
}
if(j<n)
ch++;
else
ch--;
}
cout<<endl;
}
return 0;
}