多進程程序設計課程設計
Ⅰ 操作系統課程設計編程模擬多進程共享臨界資源
我在上學時沒學好,也是和你一樣,在網上求助。只是結果不怎麼樣。還是好好學習,天天向上吧。
Ⅱ 急!!!!!!匯編程序設計課程設計
data segment
year db "year:",0ah,0dh,"$"
month db "month:",0ah,0dh,"$"
day db "day:",0ah,0dh,"$"
hour db "hour:",0ah,0dh,"$"
minute db "minute:",0ah,0dh,"$"
second db "second:",0ah,0dh,"$"
shuchu macro
mov bl,al
mov ah,al
mov cl,4
shr ah,cl
and al,0fh
add ax,3030h
push ax
mov dl,ah
mov ah,2
int 21h
pop ax
mov ah,2
mov dl,al
int 21h
endm
rcmos macro jk
mov al,jk
out 70h,al
in al,71h
cmp al,bl ;秒輸出時,是否相同
endm
ymdhm macro dz,jk1
writes dz
rcmos jk1
shuchu
cr
endm
data ends
writes macro a
lea dx,a
mov ah,9
int 21h
endm
cr macro
push ax
push dx
mov dl,0ah
mov ah,2
int 21h
mov dl,0dh
mov ah,2
int 21h
pop dx
pop ax
endm
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
ymdhm year,9
ymdhm month,8
ymdhm day,7
ymdhm hour,4
ymdhm minute,2
writes second
begin: rcmos 0
je begin ;若相同則返回
cmp al,0
jne next
push bx
push ax
ymdhm minute,2
writes second
pop ax
pop bx
next: shuchu
cr
mov ah,0bh
int 21h
cmp al,0
jnz done
jmp begin
done: mov ah,4ch
int 21h
code ends
end start
Ⅲ C語言程序設計 (學生選修課程設計)
這是我做的,你看是否滿意?可能有點大,但也沒辦法呀,你的題目也比較大,呵呵!所以,如果滿意,多給我追加點分!
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
typedef struct course
{
char number[15],name[25];
int kind,time,lessontime,practicetime,credit,term;
}type;
FILE *fp1;
void overview(); //瀏覽函數,負責瀏覽整個課程信息
void seek(); //查詢函數,負責查詢課程信息
void choose_course();//選課函數,負責讓用戶選課
void out(type temp);
void input();
int main()
{
int n,i;
if((fp1=fopen("course_information.txt","wb"))==NULL)
{printf("創建文件失敗!\n");exit(0);}
printf("請輸入要存儲的課程數目:\n");
scanf("%d",&n);
printf("開始創建文件,請輸入課程信息:\n\n");
for(i=0;i<n;i++)
{
printf("請輸入第%d門課程的信息:\n",i+1);
input();
printf("\n");
}
printf("如想瀏覽整個課程信息,請輸入1;如想查詢課程信息,請輸入2; 如想進行選課,請輸入3;如想結束選修課系統,請輸入0!\n");
while((scanf("%d",&n))!=EOF)
{
if(n==1)
overview();
if(n==2)
seek();
if(n==3)
choose_course();
if(n==0)
exit(0);
printf("\n\n如想繼續操作,只要按規則輸入你要進行的操作即可!\n規則:如想瀏覽整個課程信息,請輸入1;如想查詢課程信息,請輸入2;如想進行選課,請輸入3!\n");
}
printf("歡迎您使用此程序進行選課,謝謝!\n");
fclose(fp1);
return 0;
}
void input()
{
course c_a;
printf("請輸入課程編碼: ");
scanf("%s",c_a.number);
printf("請輸入課程名: ");
scanf("%s",c_a.name);
printf("請輸入課程性質:限選課,請輸入1;選修課,請輸入2;必修課,請輸入3! ");
scanf("%d",&c_a.name);
printf("請輸入課程總學時: ");
scanf("%d",&c_a.time);
printf("請輸入課程授課時間: ");
scanf("%d",&c_a.lessontime);
printf("請輸入課程實驗或實踐時間: ");
scanf("%d",&c_a.practicetime);
printf("請輸入課程學分: ");
scanf("%d",&c_a.credit);
printf("請輸入課程所在的學期,比如第二學期,就輸入2即可。");
scanf("%d",&c_a.term);
fwrite(&c_a,sizeof(struct course),1,fp1);//將一個結構體元素寫入文件中
}
void out(type temp)
{
printf("課程代碼: %s\n課程名: %s\n",temp.number,temp.name);
printf("課程名: %s\n",temp.name);
if(temp.kind==1)
printf("課程性質: Limited optional course\n");
else if(temp.kind==2)
printf("課程性質: Optional course\n");
else if(temp.kind==3)
printf("課程性質: Required Courses\n");
else
printf("該編碼系統不認識,即無對應的課程性質存在!\n");
printf("課程總學時: %d\n課程授課學時: %d\n實驗或上機學時: %d\n學分: %d\n課程開課學期: %d\n\n",temp.time,temp.lessontime,temp.practicetime,temp.credit,temp.term);
}
void overview()
{
rewind(fp1);
course temp;
printf("整個課程信息如下:\n");
while((fread(&temp,sizeof(type),1,fp1))!=0)
out(temp);
}
void seek()
{
int judge,credit=0,kind=0;
char a='N';
course temp;
printf("如想按學分查詢,請輸入1;如想按課程性質,請輸入2:\n");
scanf("%d",&judge);
rewind(fp1); //將文件指針位置置為開頭
if(judge==1)
{
printf("請輸入要查詢的學分:\n");
scanf("%d",&credit);
while((fread(&temp,sizeof(type),1,fp1))!=0)
if(credit==temp.credit)
out(temp);
}
else if(judge==2)
{
printf("請輸入你要查找課程的性質(限選課,請輸入1;選修課,請輸入2;必修課,請輸入3):");
scanf("%d",&kind);
while((fread(&temp,sizeof(type),1,fp1))!=0)
if(temp.kind==kind)
out(temp);
}
else
printf("不好意思,無此類查詢!\n");
}
void choose_course()
{
rewind(fp1);
course temp;
int judge=1,n=0,time=0,credit=0;
char choose[20][20];
r1: printf("請開始填寫課程編號進行選課:\n");
while(judge==1)
{
printf("請輸入你所選課程的標號: ");
scanf("%s",choose[n]);
n++;
printf("如想繼續選課,請輸入1;如想提交,請輸入0!\n");
scanf("%d",&judge);
}
while((fread(&temp,sizeof(type),1,fp1))!=0)
{
for(int i=0;i<n;i++)
if(strcmp(temp.number,choose[i])==0)
{time=time+temp.time;credit=temp.credit;break;}
}
if(time<270||credit<40)
goto r1;
printf("你所選的課為:\n");
while((fread(&temp,sizeof(type),1,fp1))!=0)
{
for(int i=0;i<n;i++)
if(strcmp(temp.number,choose[i])==0)
{out(temp);break;}
}
}
Ⅳ C語言程序設計課程設計都需要做什麼啊
我這有相似的程序,在我的作業里 給我個郵箱 我發過去
Ⅳ 《C語言程序設計》課程設計任務書 請各位高手指教啊!十萬火急!!!!
#include <graphics.h>
#include <conio.h>
#include <dos.h>
#include <malloc.h>
#include <math.h>
#define PATH "c:\\tc"
#define BK 7
#define DC 8
#define LC 15
#define P1 1
#define P2 4
#define X 121
#define Y 41
#define M 8
int newmap[26][14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2,0},
{0,2,2,0},
{0,2,0,0}
}
};
char far * bit[3],*sim;
int score,level;
/************/
int getkey();
void edge(int l,int t,int r,int b,int c1,int c2);
void init();
void new();
void newk();
void draw(int x,int y,int c);
void show();
void close();
void down();
int candown();
void tobotton();
int canturn();
void turn();
int canleft();
void left();
int canright();
void right();
int isok(int x);
void ok(int x);
void showscore();
void drawnext();
int isover();
void over();
int getkey()
{
char ch=0;
if(kbhit())
ch=getch();
return(ch);
}
void init()
{
int gdriver=DETECT,gmode;
int size,i,j;
/* registerbgidriver();*/
initgraph(&gdriver,&gmode,PATH);
setbkcolor(BK);
setfillstyle(11,8);
edge(X-9,Y-9,X+408,Y+408,DC,DC);
floodfill(1,1,DC);
edge(X-9,Y-9,X+408,Y+408,DC,LC);
edge(X-7,Y-7,X+406,Y+406,DC,LC);
edge(X-1,Y-1,X+201,Y+401,DC,LC);
edge(X-3,Y-3,X+203,Y+403,LC,DC);
edge(X+260,Y-1,X+341,Y+81,DC,LC);
edge(X+258,Y-3,X+343,Y+83,LC,DC);
size=imagesize(X+1,Y+1,X+20,Y+20);
bit[0]=(char far*)malloc(size);
if(bit[0]==NULL){sound(2000);getch();nosound();exit(1);}
getimage(X+1,Y+1,X+20,Y+20,bit[0]);
for(i=0;i<20;i++)
for(j=0;j<20;j++)
if(bmp[i][j]==1)
putpixel(X+1+j,Y+1+i,P1);
bit[1]=(char far*)malloc(size);
if(bit[1]==0){sound(2000);getch();nosound();exit(1);}
getimage(X+1,Y+1,X+20,Y+20,bit[1]);
for(i=0;i<20;i++)
for(j=0;j<20;j++)
if(bmp[i][j]==1)
putpixel(X+1+j,Y+1+i,P2);
bit[2]=(char far*)malloc(size);
getimage(X+1,Y+1,X+20,Y+20,bit[2]);
setcolor(8);
outtextxy(X+245,Y+95,"score");
outtextxy(X+320,Y+95,"level");
edge(X+240,Y+107,X+290,Y+122,LC,DC);
edge(X+242,Y+109,X+288,Y+120,DC,LC);
edge(X+315,Y+107,X+365,Y+122,LC,DC);
edge(X+317,Y+109,X+363,Y+120,DC,LC);
size=imagesize(X+240,Y+107,X+290,Y+122);
sim=(char far *)malloc(size);
getimage(X+240,Y+107,X+290,Y+122,sim);
edge(X+207,Y+133,X+400,Y+401,LC,DC);
edge(X+210,Y+135,X+397,Y+398,LC,DC);
outtextxy(X+213,Y+140,"Control Option:");
outtextxy(X+213,Y+150,"-----------------");
outtextxy(X+213,Y+160," [P]--Start/Pause");
outtextxy(X+213,Y+177," [Esc]--Quit the game");
outtextxy(X+213,Y+194," [W]--Turn");
outtextxy(X+213,Y+211," [A]--Left");
outtextxy(X+213,Y+228," [S]--Down fast");
outtextxy(X+213,Y+245," [D]--Right");
outtextxy(X+213,Y+262,"[Space]--Down to botton");
for(i=0;i<4;i++)
edge(X+213+i*3,Y+278+i*4,X+394-i*3,Y+391-i*4,DC,LC);
outtextxy(X+224,Y+300," This game was");
outtextxy(X+224,Y+312,"programed by jackin.");
outtextxy(X+224,Y+324," If you discover" );
outtextxy(X+224,Y+336,"errors in it ,please");
outtextxy(X+224,Y+348," email to:");
setcolor(4);
outtextxy(X+224,Y+360," [email protected]");
if(bit[0]==0||bit[1]==0||bit[2]==0||sim==0)
{
close();
exit(1);
}
putimage(X+1,Y+1,bit[0],0);
}
void edge(int l,int t,int r,int b,int c1,int c2)
{
int cl=getcolor();
setcolor(c1);
line(l,t,r-1,t);
line(l,t,l,b-1);
setcolor(c2);
line(r,t,r,b);
line(l,b,r,b);
setcolor(cl);
}
void draw(int x,int y,int c)
{
putimage(X+20*y,Y+x*20,bit[c],0);
}
void show()
{
int i,j;
for(i=0;i<20;i++)
for(j=0;j<10;j++)
if(map[1][i+4][j+2]!=map[0][i+4][j+2])
{
map[0][i+4][j+2]=map[1][i+4][j+2];
draw(i,j,map[1][i+4][j+2]);
}
}
void close()
{
int i;
for(i=0;i<3;i++)
free(bit[i]);
free(sim);
closegraph();
}
void new()
{
int i,j,t=-1;
score=0;
level=1;
showscore();
for(i=0;i<26;i++)
for(j=0;j<14;j++)
{
map[1][i][j]=newmap[i][j];
map[0][i][j]=0;
}
for(;t<0;)
t=rand();
next=t%M;
}
void newk()
{
int i,j,t=-1;
xx=1;
yy=5;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
map[1][xx+i][j+yy]=kk[next][i][j];
for(;t<0;)
t=rand();
next=t%M;
show();
}
int candown()
{
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{
if(map[1][xx+i][yy+j]==2&&map[1][xx+i+1][yy+j]==1)
return(0);
}
return(1);
}
void down()
{
int i,j;
xx++;
for(i=3;i>=0;i--)
for(j=3;j>=0;j--)
{
if(map[1][xx+i-1][yy+j]!=1)
{
if(map[1][xx+i][yy+j]!=1)
map[1][xx+i][yy+j]=map[1][xx+i-1][yy+j];
}
else
{
if(map[1][xx+i][yy+j]!=1)
map[1][xx+i][yy+j]=0;
}
}
for(j=0;j<4;j++)
if(map[1][xx-1][yy+j]==2)
map[1][xx-1][yy+j]=0;
}
void tobotton()
{
int i,j;
for(i=3;i>=0;i--)
for(j=3;j>=0;j--)
if(map[1][xx+i][yy+j]==2)
map[1][xx+i][yy+j]=1;
}
int canturn()
{
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(map[1][xx+3-j][i+yy]==1&&map[1][xx+i][j+yy]==2)
return(0);
return(1);
}
void turn()
{
int i,j,t[4][4];
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(map[1][xx+i][j+yy]==1)
t[i][j]=0;
else
t[i][j]=map[1][xx+i][j+yy];
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(map[1][xx+i][j+yy]!=1)
map[1][xx+i][j+yy]=t[j][3-i];
}
int canleft()
{
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{
if(map[1][xx+i][yy+j]==2&&map[1][xx+i][yy+j-1]==1)
return(0);
}
return(1);
}
void left()
{
int i,j;
yy--;
for(i=3;i>=0;i--)
for(j=0;j<4;j++)
{
if(map[1][xx+i][yy+j+1]!=1)
{
if(map[1][xx+i][yy+j]!=1)
map[1][xx+i][yy+j]=map[1][xx+i][yy+j+1];
}
else
{
if(map[1][xx+i][yy+j]!=1)
map[1][xx+i][yy+j]=0;
}
}
for(j=0;j<4;j++)
if(map[1][xx+j][yy+4]==2)
map[1][xx+j][yy+4]=0;
}
int canright()
{
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{
if(map[1][xx+i][yy+j]==2&&map[1][xx+i][yy+j+1]==1)
return(0);
}
return(1);
}
void right()
{
int i,j;
yy++;
for(i=3;i>=0;i--)
for(j=3;j>=0;j--)
{
if(map[1][xx+i][yy+j-1]!=1)
{
if(map[1][xx+i][yy+j]!=1)
map[1][xx+i][yy+j]=map[1][xx+i][yy+j-1];
}
else
{
if(map[1][xx+i][yy+j]!=1)
map[1][xx+i][yy+j]=0;
}
}
for(j=0;j<4;j++)
if(map[1][xx+j][yy-1]==2)
map[1][xx+j][yy-1]=0;
}
int isok(int x)
{
int i;
if(x>23)return(0);
for(i=2;i<12;i++)
if(map[1][x][i]==0||map[1][x][i]==2)
return(0);
return(1);
}
void ok(int x)
{
int i;
for(;x>0;x--)
for(i=2;i<12;i++)
map[1][x][i]=map[1][x-1][i];
score++;
level=score/10+1;
}
void showscore()
{
char s[20],l[20];
itoa(score,s,10);
itoa(level,l,10);
putimage(X+240,Y+107,sim,0);
putimage(X+315,Y+107,sim,0);
outtextxy(X+244,Y+111,s);
outtextxy(X+325,Y+111,l);
}
void drawnext()
{
int x,y;
for(x=0;x<4;x++)
for(y=0;y<4;y++)
{
putimage(X+261+20*y,Y+x*20,bit[kk[next][x][y]],0);
}
}
int isover()
{
int i;
for(i=2;i<12;i++)
if(map[1][3][i]==1)return(1);
return(0);
}
void over()
{
int i,j;
for(i=23;i>3;i--)
{
for(j=2;j<12;j++)
map[1][i][j]=1;
show();
delay(1000);
}
for(i=4;i<24;i++)
{
for(j=2;j<12;j++)
map[1][i][j]=0;
show();
delay(1000);
}
}
main()
{ int graphdriver=DETECT;
int graphmode;
int i,j;
char cc;
init();
start:
cc=getkey();
for(;cc!='p'&&cc!='P';)
{
rand();
if(cc==27)goto end;
cc=getkey();
}
new();
newk();
for(;;)
{
for(i=0;i<20000-level*1000;i++)
{
switch(getkey())
{
case 27:
over();
goto end;
case 'w':
case 'W':
if(canturn())
turn();
break;
case 'a':
case 'A':
if(canleft())
left();
break;
case 's':
case 'S':
if(candown())
{
down();
}
else
{
}
break;
case 'd':
case 'D':
if(canright())
right();
break;
case ' ':
for(;candown();)
down();
break;
case 'p':
case 'P':
cc=getkey();
for(;cc!='p'&&cc!='P';)
{
if(cc==27)goto end;
cc=getkey();
}
break;
default:break;
}
show();
}
drawnext();
if(candown())
{
down();
show();
}
else
{
tobotton();
for(j=1;j<24;j++)
if(isok(j))
{
ok(j);
score++;
showscore();
}
if(isover())
{
over();
goto start;
}
newk();
show();
}
}
end:
close();
getch();
}
Ⅵ 操作系統課程設計作業 很急!題目是Windows平台上的多進程(線程)編程
你好,
這種問題是沒有人會來幫助你的,網友們能幫你的只能是方法,如果你想不勞而獲,那你就不用來這里浪費時間了。
Ⅶ C語言程序設計課程設計!
圖書借閱管理,C語言編程的,只要設計部分的,,m
Ⅷ linux課程設計具有多進程處理的聊天程序設計
多線程程序設計的概念早在六十年代就被提出,但直到...2.2 Linux 下的進程式控制制 在傳統的Unix 環境下,有...其實UNIX 自有其解決 的辦法,
Ⅸ 《C語言程序設計》課程設計
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#define BUFFERSIZE 1024
#define MAXACCOUNT 1000
typedef struct BankAccount
{
int account;
int key;
char name[32];
float balance;
}BANKACCOUNT;
BANKACCOUNT accountCollection[MAXACCOUNT];
int curAccount = 0;
void InsertAccount(FILE *fp)
{
BANKACCOUNT newaccount;
printf("please input the account information\n");
printf(">>account num:");
scanf("%d",&(newaccount.account));
printf(">>key:");
scanf("%d",&(newaccount.key));
printf(">>name:");
scanf("%s",newaccount.name);
printf(">>balance:");
scanf("%f",&(newaccount.balance));
fseek(fp,0L,SEEK_END);
fprintf(fp,"%d %d %s %.2f\n",newaccount.account,newaccount.key,newaccount.name,newaccount.balance);
}
void GetAccount(FILE *fp)
{
int accountnum;
int key;
char name[32];
float balance;
int i =0,j;
char buffer[BUFFERSIZE];
int len;
curAccount = 0;
fseek(fp,0,SEEK_SET);
while(!feof(fp)) /* 因為feof()最後會讀2遍,所以最後curAccount多加了1 */
{
fscanf(fp,"%d %d %s %f",&accountnum,&key,name,&balance);
accountCollection[curAccount].account = accountnum;
accountCollection[curAccount].key = key;
strcpy(accountCollection[curAccount].name ,name);
accountCollection[curAccount].balance = balance;
curAccount++;
}
}
void ListAccount(FILE *fp)
{
int i =0;
printf("There is %d accounts at all:\n",curAccount-1);/* curAccount減去多加的1 */
for(i = 0;i< curAccount-1;i++)
{
printf("ACCOUNT[%d]:\n",i+1);
printf("account:%d\n",accountCollection[i].account);
printf("name:%s\n",accountCollection[i].name);
printf("balance:%.2f\n",accountCollection[i].balance);
}
}
int SearchAccount(FILE *fp,int accountnum)
{
int i =0;
for(i = 0;i< curAccount-1;i++)
{
if(accountCollection[i].account == accountnum)
{
printf("ACCOUNT[%d]:\n",i+1);
printf("account:%d\n",accountCollection[i].account);
printf("name:%s\n",accountCollection[i].name);
printf("balance:%.2f\n",accountCollection[i].balance);
return 1;
}
}
return 0;
}
void DelAccount(FILE *fp,int accountnum)
{
int i;
if(SearchAccount(fp,accountnum)==0)
printf("Can't find the account\n");
else
{
for(i = 0;i<curAccount-1;i++)
{
if(accountCollection[i].account != accountnum)
fprintf(fp,"%d %d %s %.2f\n",accountCollection[i].account,accountCollection[i].key,accountCollection[i].name,accountCollection[i].balance);
}
printf("delete successfully!\n");
}
}
int main()
{
FILE *fp;
int accountnum;
int i;
do{
system("cls"); //清屏
puts("********************************************");
puts("* You can choose : *");
puts("* 1 : Insert a new Account *");
puts("* 2 : List all Accounts *");
puts("* 3 : Find a Account *");
puts("* 4 : Delete a Account *");
puts("* 5 : quit *");
puts("********************************************");
printf("Please input your choice:");
scanf("%d",&i);
system("cls"); //清屏
switch(i)
{
case 1:
if(!(fp = fopen("account.txt","a+")))
{
printf("can't open the file account.txt\n");
exit(0);
}
InsertAccount( fp);
printf("press any key to continue.....\n");
getch();
fclose(fp);
break;
case 2:
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
ListAccount(fp);
fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
case 3:
printf("please input the account num:\n");
scanf("%d",&accountnum);
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
if(!SearchAccount(fp,accountnum))
printf("There is not the account:%d\n",accountnum);
fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
case 4:
printf("please input the account num:\n");
scanf("%d",&accountnum);
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
fclose(fp);
if(!(fp = fopen("account.txt","w+")))
{
printf("can't open the file account.txt\n");
exit(0);
}
DelAccount(fp,accountnum);
fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
default:
break;
}
}while(i != 5);
return 0;
}
賬戶數據文件名已經設定為account.txt,這個文件要和上面這個程序放在同一個文件夾下面,不然就得用絕對路徑(比如"d:\\book\\account.txt"),account內容可以用記事本打開自己改動,然後運行程序後就可以在程序中添加或刪除
Ⅹ 求2個程序設計方法C++程序,課程設計用。
#include<iostream>
using namespace std;
int a[10];
int main()
{
void getdata();
void sort(int array[],int n);
getdata();
sort(a,10);
cout<<"降序排列的數組為:";
for(int i=0;i<10;i++)
cout<<a[i]<<" ";
cout<<endl;
return 0;
}
void getdata()
{
cout<<"請輸入數據:";
for(int i=0;i<10;i++)
cin>>a[i];
}
void sort(int array[],int n)
{
int i,j,t;
for(j=0;j<9;j++)
for( i=0;i<9-j;i++)
if(array[i]<array[i+1])
{
t=array[i];
array[i]=array[i+1];
array[i+1]=t;
}
}
#include <iostream>
using namespace std;
int units[]={1,11,111,1111,11111,111111,1111111,11111111,111111111};
int main()
{
int a,n;
cout<<"Enter a:"<<endl;
cin>>a;
cout<<"Enter n:"<<endl;
cin>>n;
int s=units[n-1];
for(int i=n-2;i>=0;i--)
{
s-=units[i];
}
cout<<s*a<<endl;
}