C TEST 1
Specify
the output of the following code:
1)
#include <stdio.h>
#include <conio.h>
int main(void)
{
int i=0, x=0;
for (i=1; i <10; i = i+1)
{
if ( i % 2 == 0)
x = x + i;
else
x = x – 1;
}
printf(“The value
of x is %d”,x);
}
|
2)
#include <stdio.h>
#include <conio.h>
int main(void)
{
int n, digit, sum
= 0;
n = 3456;
for (i =1 ;i
<=4;i++)
{
digit = n % 10;
printf ( “ digit
is %d\n”,digit);
sum = sum +
digit;
n = n / 10;
}
printf(“the sum of digits are %d”, sum);
}
|
3)
#include <stdio.h>
#include <conio.h>
int main(void)
{
clrscr();
int prod =1, i ;
for ( i = 2; i
< 30 ; i = i +1)
{
if ( i % 3 == 0)
printf(“The no
is %d”, i);
}
}
|
4)
#include <stdio.h>
#include <conio.h>
int main(void)
{
clrscr();
int prod =1;
for ( i = 30; i
> 1 ; i=i-1)
{
if ( i % 5 == 0)
printf(“The no
is %d”, i);
}
}
|
5)
#include <stdio.h>
#include <conio.h>
int main(void)
{
char ch =’s’;
clrscr();
switch(ch)
{
case ‘a’:
case ‘A’:
printf(“Hello”);
break;
default:
printf(“Bye”);
break;
}
getch();
return 0;
}
|
6)
#include <stdio.h>
#include <conio.h>
int main(void)
{
char ch = ‘z’;
clrscr();
switch(ch)
{
case ‘a’:
case ‘A’:
printf(“Hello”);
break;
case ‘j’:
printf(“Bye”);
break;
}
getch();
return 0;
}
|
havy
ReplyDelete