PARKSIDE'S TRIANGLE is generated from two numbers--the size
and the seed. The size determines how many rows are in the triangle
and the seed determines the first number in the triangle. Here are two
examples:
SIZE 6,SEED 1 SIZE 5, SEED 3
1 2 4 7 2 7 3 4 6 9 4
3 5 8 3 8 5 7 1 5
6 9 4 9 8 2 6
1 5 1 3 7
6 2 8
3
โจทย์มีแค่นี้คับ แต่ทำมะได้ซักที ขอคำแนะนำหน่อยคับ???
ใครก็ได้ช่วยหน่อยคับ ลองหลายวิธียังมะได้เลย
Moderators: mindphp, ผู้ดูแลกระดาน
-
- PHP Newbie
- Posts: 1
- Joined: 25/03/2011 11:57 pm
-
- PHP Super Member
- Posts: 480
- Joined: 25/01/2010 11:57 pm
- Contact:
Re: ใครก็ได้ช่วยหน่อยคับ ลองหลายวิธียังมะได้เลย
แบบนี้ใช่ไหม
SIZE 6,SEED 1
1 2 4 7 2 7
3 5 8 3 8
6 9 4 9
1 5 1
6 2
3
SIZE 5, SEED 3
3 4 6 9 4
5 7 1 5
8 2 6
3 7
8
Code: Select all
#include<stdio.h>
void main(void)
{
int size,seed,temp;
printf("Enter Size:");
scanf("%d",&size);
printf("Enter Seed:");
scanf("%d",&seed);
for(int i=1;i<=size;i++)
{
temp=seed;
seed+=i;
if(seed>9)
seed-=9;
for(int j=i-1;j<size;j++)
{
temp+=j;
if(temp>9)
temp-=9;
printf("%d ",temp);
}printf("\n");
}
}
1 2 4 7 2 7
3 5 8 3 8
6 9 4 9
1 5 1
6 2
3
SIZE 5, SEED 3
3 4 6 9 4
5 7 1 5
8 2 6
3 7
8
Who is online
Users browsing this forum: No registered users and 5 guests