Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.
/**Bismillahir Rahmanir Rahim.**/ #include <stdio.h> int main() { int n, i, j, cnt=0; while(scanf("%d", &n) != EOF) { int num = 1; cnt++; num += ((n*(n + 1)) / 2); if(n == 0) printf("Caso %d: %d numero\n", cnt, num); else printf("Caso %d: %d numeros\n", cnt, num); printf("0"); for(i=1; i<=n; i++) { for(j=1; j<=i; j++) printf(" %d", i); } printf("\n\n"); } return 0; }
vai apnar num songkhay vul asce... tai error dekhacce..
ReplyDeleteদুঃখিত।
Deleteআমি কোন ভুল পাচ্ছি না।
num সংখ্যা ঠিক আছে।
আর এই solution সব টেস্ট কেস পাশ হইতে পারছে।
ধন্যবাদ।
alsalam alykom
ReplyDeletewhen write num+=n*(n+1)/2 why don't we write num+=n
thanks
Suppose, for n = 3, their contain 7 number on the sequence.
DeleteAnd we get this by using this law.
Initially 'num' is equal 1.
so, num+=n*(n+1)/2;
=> num = num + n*(n+1)/2;
=> num = 1 + 3*(3+1)/2;
.'. num = 7
This comment has been removed by the author.
Deletethat's right I understand when write n=3 as the first input this output 7 number so when I write num=1 in first code not in looping and num+=n this is making num depend on the n=0,1,2 that's not written as first inputs
Delete#include
ReplyDeletevoid main()
{
int n, i=1, count, j, k;
while(scanf("%d",&n)!=EOF){
count=1;
for(j=1;j<=n;j++)count+=j;
if(n==0)printf("Caso %d: 1 numero\n", i);
else printf("Caso %d: %d numero\n", i, count);
printf("0");
for(j=0;j<=n;j++){
for(k=0;k<j;k++){
printf(" %d",j);
}
}printf("\n\n");
i++;
}
}
#include
ReplyDeletevoid main()
{
int n, i=1, count, j, k;
while(scanf("%d",&n)!=EOF){
count=1;
for(j=1;j<=n;j++)count+=j;
if(n==0)printf("Caso %d: 1 numero\n", i);
else printf("Caso %d: %d numero\n", i, count);
printf("0");
for(j=0;j<=n;j++){
for(k=0;k<j;k++){
printf(" %d",j);
}
}printf("\n\n");
i++;
}
}
Whats wrong in it sir?
ar IF ELSE er ki kono dorkar ase eikhane?
ReplyDeletewhere is the problem ,,seen,,presentation error ,,can anyone say?///
ReplyDelete#include
using namespace std;
int main()
{
int n,i,j,k=0,l;
while(scanf("%d",&n)!=EOF)
{
k++;
i=0;
if(n==0)
{
i=1;
cout<<"Caso "<<k<<": "<<i<<" numero"<<endl;
printf("%d\n\n",n);
}
else
{
i=1;
for(j=1; j<=n; j++)
{
i+=j;
}
cout<<"Caso "<<k<<": "<<i<<" numeros"<<endl;
for(j=0; j<=n; j++)
{
if(j==0)
{
cout<<j<<" ";
}
else
{
for(l=1; l<=j; l++)
{
cout<<j<<" ";
}
}
}
printf("\n\n");
}
}
return 0;
}