You are not logged in. Please login at www.codechef.com to post your questions!

×

what is the diference between these two codes ? i m not able to figure out.

include<stdio.h>

int main() { int t,n,r,sum; scanf("%d",&t); while(t--) { sum=0; scanf("%d",&n); while(n>0) { r=n%10; sum=sum+r; n=n/10; } printf("%d\n",sum); } }

second code

include<stdio.h>

int main() {int t,n,a=0,s=0,i; printf("enter the no of test cases"); printf("\n");
printf("\n");
scanf("%d",&t); while(t--) { printf("enter the number "); printf("\n");
scanf("%d",&n); printf("\n");
s=0;a=0; while(n>0) { a=n%10; s=s+a; n=n/10; } printf("sum of digits=%d",s); printf("\n");

  }
return 0;}

asked 12 Oct '18, 17:24

chaitanysarasw's gravatar image

0★chaitanysarasw
1
accept rate: 0%

Dont use random print statements, its a machine checking your output to be exact match of expected output. Output ONLY whats asked and in that format only.

(12 Oct '18, 17:49) vijju123 ♦♦5★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×678

question asked: 12 Oct '18, 17:24

question was seen: 69 times

last updated: 12 Oct '18, 17:49