Unlocking the Basics of C Programming: Essential Looping Exercises for Grade 10 and SEE Students
(It carries 2 Marks)
1.
(Specification Grid 2077) WAP to
print the series with their sum. 1,2,3,4,….., up to 10th terms.
#include<stdio.h> int main() { int
x,sum=0; for(x=1;x<=10;x++) { printf("%d\n",x); sum=sum+x; } printf("sum=%d",sum); return
0; }
2. (SEE 2078) To
display the first 10 odd numbers. #include<stdio.h> int main() { int x,a=1; for(x=1;x<=10;x++) { printf("%d\t",a); a=a+2; } return 0; } |
3. (SEE
Promotion Grade Exam 2078) To display the series 2,4,6,8 upto
10th term. #include<stdio.h> int main() {
int x,a=2;
for(x=1;x<=10;x++)
{
printf("%d\t",a);
a=a+2;
} return 0; }
4. (SEE 2079) Write a program in C-language to display the
series with their sum. 1,2,3,4,.....up
to 10th term. int main() { int
x, sum=0; for(x=1;x<=10;x++) { printf("%d\t",x); sum=sum+x; } printf("\nsum=%d",sum); return 0; }
|
5. Pabson Pre-Board exam 2079 Write a program in ‘C’ language to
display first 10 natural
numbers. Ans: #include <stdio.h> int main() { int i; for (i = 1; i <= 10;
i++) {
printf("%d ", i); }
return 0; }
6. To
display the first 10 natural numbers (1 to 10) horizontally. #include<
stdio.h> int main() { int x; for(x=1;x<=10;x++) { printf("%d\t",x); } return 0; } |
7. To display the numbers 10 to 1
reverse order in vertical form. #include<
stdio.h> int main() { int x; for(x=1;x<=10;x++) { printf("%d\n",x); } return 0; }
8. To display the numeric series 1
3 5 7 9......49. #include<stdio.h> int main() { int x=1; do { printf("%d\n",x); x=x+2; }while(x<=50); return 0; } |
9. To
display the sum of first 10 natural numbers. #include<stdio.h> #include<conio.h> void main() { int x=1,s=0; while(x<=10) { s=s+x; x=x+1; } printf("sum=%d",s); getch(); }
10. Write
a program in C language to display the first 10 odd numbers. #include<stdio.h> int main() { int
x,a=1; for(x=1;x<=10;x++) { printf("%d\t",a); a=a+2; } return 0; }
|
11, To
display the series of even number upto 100. #include<stdio.h> int main() { int i; printf("The
series of even number is"); for(i=2;i<=100;i=i+2) { printf("%d\t",i); } return 0; }
12. To
display the series of number 4 16 36
64.......10th term. #include<stdio.h> int main() { int i, a=2; for(i=1;i<=10;i++) { printf("%d\t",a*a); a=a+2; } return 0; } |
13. To
input any number and display its multiplication table. #include<stdio.h> int main() { int i, n; printf("Enter
which number table\n"); scanf("%d",&n); for(i=1;i<=10;i++) { printf("%d\n",n*i); } return 0 }
14. WAP
to display Fibonacci series upto 10 terms [ e.g.
1,1,2,3,5,8,13,21.......]. #include<stdio.h> int main() { int
a=1,b=1,i; for(i=1;i<=5;i++) { printf("%d\t%d\t",a,b); a=a+b ; b=a+b; } return 0; } |
15. To display the series 1 11
111 1111 11111. #include<stdio.h> int main() { int x=1,a=1; while(x<=5) { printf("%d\t",a); a=a*10+1; x=x+1; } return 0; }
16. To display the series 22222 2222
222 22 2 #include<stdio.h> int main() { int x=1;
a=22222; while(x<=5) { printf("%d\t",a); a=(a-2)/10; x=x+1; } return 0; } |
17. To
display the series 5 10 15 20 ………50 #include<stdio.h> int main() { int x; for(x=5;x<=50;x=x+5) { printf("%d\t",x); } return 0; }
18. WAP to print the numbers from 1 to 100
using a while loop. #include<stdio.h> int main() { int
x=1; while(x<=100) { printf("%d\t",x); x=x+1; }
return
0; }
|
19. To
display the first 20 even numbers. #include<stdio.h> int main() { int x=1,a=2; while(x<=20) { printf("%d\t",a); a=a+2; x=x+1; } return 0; } 20. WAP to input any number and display
its factorial number. Note: A factorial number is the
product of all the positive integers less than or equal to a given number.
For example, 5 = 5 x 4 x 3 x 2 x 1 = 120. #include<stdio.h> int main() {
int number, i;
long f = 1;
printf("Enter a non-negative integer: ");
scanf("%d", &number); for (i = 1; i <= number; i++) { f= f*i;
}
printf("The factorial of %d is %lld.\n", number, f);
return 0; } |
21. WAP to check whether input
number is prime or composite. #include <stdio.h> int main() {
int num, i, t=0;
printf("Enter any number: \n");
scanf("%d",&num);
for(i=2;i<=num-1;i++)
{
if(num%i==0)
t++;
} if(t==0) printf("prime
no"); else printf("composite
no"); }
22. WAP to input any digit and
display its sum. #include <stdio.h> int main() {
int num, sum = 0, digit;
printf("Enter a number: ");
scanf("%d", &num); // Calculate the sum of the digits in
the input number
while (num > 0) { digit = num % 10; sum= sum+digit; num=num/10;
}
// Display the result
printf("The sum of the digits is %d.", sum);
return 0; } |
23. WAP to find the reverse of an
input digit. #include<stdio.h> int main() { int
num,r,s=0; printf("Enter
any number "); scanf("%d",&num); while(num!=0) { r=num%10; s=s*10+r; num=num/10; } printf("Reverse
number = %d",s); return
0; } 24) C
program to display 100,98,94,88,80,..... up to 10th terms #include
<stdio.h> int main() { int i,b=100,c=2; for(i=0;i<10;i++) { printf("%d\n",b); b=b-c; c=c+2; }
return 0; } 25) C
program to display 2,8,18,32,..... up to 10th terms #include
<stdio.h> int main() { int x,a; for(x=1;x<=10;x++) { a=x*x*2; printf("%d\n",a); }
return 0; } 26) To
display 1,2,4,8,16,..... up to 10th terms #include
<stdio.h> int main() { int x,a=1; for(x=0;x<10;x++) { printf("%d\n",a); a=a*2; }
return 0; } Write a program in 'C' language to input number and check whether it is a palindrome or not. #include<stdio.h> int main() { int n,r,t,a; printf("Enter any number:"); scanf("%d",&n); a=n; while (n>0) { r=n%10; t=t*10+r; n=n/10; } if(a==t) printf("number is palindrom"); else printf("number is not palindorm"); return 0; } |
You may alo read:
Qbasic looping with sub procedure
No comments:
Post a Comment