Set 1:Q1-Q4 Set 2:Q5-Q8
Question:1
Write a C program to print numbers from 1 to 10 (using goto labelname)?
Sol:
#include <stdio.h>
int main()
{
int i=1;
abc:
printf("%d\n",i);
i=i+1;
if(i<=10)
goto abc;
return 0;
}
Output:
1
2
3
4
5
6
7
8
9
10
Question: 2
Write a C program to print numbers all even number upto 20 (using goto labelname)?
Sol:
#include <stdio.h>
int main()
{
int i=2;
abc:
printf("%d\n",i);
i=i+2;
if(i<=20)
goto abc;
return 0;
}
Output:
2
4
6
8
10
12
14
16
18
20
Question: 3
Write a C program to print numbers all odd number upto 25 (using goto labelname)?
Sol:
#include <stdio.h>
int main()
{
int i=1;
abc:
printf("%d\n",i);
i=i+2;
if(i<=25)
goto abc;
return 0;
}
Output:
1
3
5
7
9
11
13
15
17
19
21
23
25
Question: 4
Write a C program to print numbers all multiples of 5 upto 100 (using goto labelname)?
Sol:
#include <stdio.h>
int main()
{
int i=5;
abc:
printf("%d\n",i);
i=i+5;
if(i<=100)
goto abc;
return 0;
}
Output:
5
10
15
20
25
30
35
40
45
50
55
60
65
70
75
80
85
90
95
100




