My issue
can’t we solve the problem by using for loop
My code
#include <stdio.h>
int main(void) {
// your code goes here
int a,b,t,i;
scanf("%d",&t);
for(i=0;i<t;i++){
scanf("%d",&a,&b);
printf("%d",a+b);}
return 0;
}
Learning course: Practice C
Problem Link: CodeChef: Practical coding for everyone
In scanf you have to take one more %d for taking input b and also print \n after each test case.
we can solve this problem also using while loop.
include <stdio.h>
int main(void) {
// your code goes here
int a,b,t,i;
scanf(“%d”,&t);
for(i=0;i<t;i++){
scanf("%d %d",&a,&b);
printf("%d\n",a+b);}
return 0;
}
anup001
September 24, 2023, 4:02pm
3
instead of “for(i=0;i<t;i++)” you can just do while(t—)
scanf(“%d%d”,&a,&b);
scanf(“%d\n”,a+b);