C Programming Questions with their programs.
1. Write C program to display the series: 1,2,3,6,11,20,37 .... up to 10th terms
#include<conio.h>
void main() {
int i, first = 1, second = 2, next;
printf("The first 10 terms of the series are: \n");
for (i = 1; i <= 10; i++) {
printf("%d, ", first);
next = first + second;
first = second;
second = next;
}
printf("\n");
getch( );
}
#include<conio.h>#include <stdio.h>
void main() {
int n, i, flag = 0;printf("Enter a positive integer: ");scanf("%d", &n);for (i = 2; i <= n/2; i++) {if (n%i == 0) {flag = 1;break;}}if (flag == 1) {printf("%d is a composite number\n", n);} else {printf("%d is a prime number\n", n);}
getch( );}
3. Write a program to find the factorial of a given number:
#include<conio.h>#include <stdio.h>
void main() {
int n, i, fact= 1;
printf("Enter an integer: ");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
fact =fact*i ;
}
printf("Factorial of %d = %d", n, factorial);
getch( );
}
4. Write a program to find the sum of natural numbers up to n:
#include <stdio.h>
#include<conio.h>
void main() {
int n, i, sum = 0;
printf("Enter an integer: ");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
sum =sum+ i;
}
printf("Sum of natural numbers up to %d = %d", n, sum);
getch( );
}
#include <stdio.h>
}
Netra Koirala
Computer Science Educator
Passionate computer science educator and author. Provides free study notes, practical guides, and tutorials for Class 9, 10, 11, 12, and B.Sc CSIT students in Nepal. Years of teaching experience in computer science fundamentals.
LinkedIn ProfileRelated Posts
Loading related posts…
Computer Science notes, tutorials, MCQs, and educational resources for Nepal students. Covering Class 9, SEE preparation, Class 11, Class 12, SLC, programming, DBMS, networking, HTML, JavaScript, PHP, OOP and more.
Featured Post
Grade 10 Computer Science: Specification Grid & Model Questions
Specification Grid & Model Questions of Computer Science | Grade 10 📚 Examination Resource Specification Grid & M...
