What is the output of the c program shown below when the user enters the followi
ID: 3851415 • Letter: W
Question
What is the output of the c program shown below when the user enters the following 10 -5 20-10-15 data as input? #include Hinclude int main (void) int a b, x 0, y 0; for (a 1 a 5 a++) scanf ("sd", 6b) if (b 0) x m x b else y bo printf ("8d and 8dIn x, y) char str "alabama" b* strlen (str); for (a b-1: a 0; a--) if (str [a] a printf ("A") else printf ("sc", str [a]) printf ("In") return 0; What is the output of the c program shown below when the user enters the following data as input? 2 4 6 5 8 include includeExplanation / Answer
1st sum
#include<stdio.h>
#include<string.h>
int main()
{
int a,b,x=0,y=0;
for(a=1;a<=5;a++)
{
scanf("%d",&b);//taking inputs 10 -5 20 -10 -5
if(b>=0)//if b>=0
x=x+b;//x=0+10;x=10+20
else
y=y+b;//y=0-5;y=-5-10;y=-15-5;
}
printf("%d and %d ",x,y);//so x=30,y=-20
char str[]="alabama";
b=strlen(str);//7
for(a=b-1;a>=0;a--)//start from last index of array
{
if(str[a]=='a')
printf("A");//a is replaced by A
else
printf("%c",str[a]);// then it is printed as AlAbAmA
}
printf(" ");
return 0;
}
out put
10
-5
20
-10
-5
30 and -20
AmAbAlA
-------------------------------------------------------------------------------------------------------------------------------------------------
2nd sum
#include<stdio.h>
#include<string.h>
int main()
{
int a=0,b;
while(a<20)//a=25
{
scanf("%d",&b);//input 2 4 6 5 8
a=a+b;//a=2+4+6+5+8
}
printf("%d ",a);//a=25
char str[]="abcdefghij";
b=strlen(str);
for(a=0;a<b;a=a+2)
printf("%c ",str[a]);// it prints every even bit a c e g i as a=a+2;
return 0;
}
out put
2
4
6
5
8
25
a
c
e
g
i
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.