0% found this document useful (0 votes)
14 views11 pages

D Lab 3

This document is an assignment from Southeast University on the programming language C, submitted by Tanzir Ahmed. It includes ten exercises demonstrating various programming concepts such as loops, functions, and number manipulation. Each exercise is presented with its corresponding C code implementation.

Uploaded by

sherlockisgenius
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views11 pages

D Lab 3

This document is an assignment from Southeast University on the programming language C, submitted by Tanzir Ahmed. It includes ten exercises demonstrating various programming concepts such as loops, functions, and number manipulation. Each exercise is presented with its corresponding C code implementation.

Uploaded by

sherlockisgenius
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

SOUTHEAST UNIVERSITY

Assignment
On
“Programming language c”

Assignment 03

Submitted from : Submitted to:

Tanzir Ahmed “Tahsina muthaki”


Id :2024200000321 Lecturer,Dept of CSE
Type your text
Batch : 68 Southeast University
Course code:162.16

Date of submission : 18/03/2025


Exercise 01:

#include <stdio.h>
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
while (n > 0) {
printf("%d ", n);
n--;
}
return 0;
}
Exercise 02:

#include <stdio.h>
int main() {
int i = 2;
while (i <= 100) {
printf("%d ", i);
i += 2;
}
return 0;
}
Exercise 03:

#include <stdio.h>
int main() {
int n, sum = 0;
printf("Enter a number: ");
scanf("%d", &n);
for (int i = 1; i <= n; i += 2) {
sum += i;
}
printf("Sum of odd numbers: %d", sum);
return 0;
}
Exercise 04 :

#include <stdio.h>
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
for (int i = 1; i <= 10; i++) {
printf("%d x %d = %d\n", n, i, n * i);
}
return 0;
}
Exercise 05 :

#include <stdio.h>
int main() {
int n, sum = 0;
printf("Enter a number: ");
scanf("%d", &n);
while (n > 0) {
sum += n % 10;
n /= 10;
}
printf("Sum of digits: %d", sum);
return 0;
}
Exercise 06 :

#include <stdio.h>
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
printf("Factors of %d are: ", n);
for (int i = 1; i <= n; i++) {
if (n % i == 0)
printf("%d ", i);
}
return 0;
}
Exercise 07 :

#include <stdio.h>
int isPrime(int num) {
if (num < 2) return 0;
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) return 0;
}
return 1;
}
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
printf("Prime numbers: ");
for (int i = 2; i <= n; i++) {
if (isPrime(i))
printf("%d ", i);
}
return 0;
}
Exercise 08 :

#include <stdio.h>
#include <math.h>
int main() {
int n, temp, sum = 0, digits = 0;
printf("Enter a number: ");
scanf("%d", &n);
temp = n;
while (temp > 0) {
temp /= 10;
digits++;
}
temp = n;
while (temp > 0) {
sum += pow(temp % 10, digits);
temp /= 10;
}
if (sum == n)
printf("%d is an Armstrong number.", n);
else
printf("%d is not an Armstrong number.", n);
return 0;
}
Exercise 09:

#include <stdio.h>
int main() {
int n, sum = 0;
printf("Enter a number: ");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
sum += i * i;
}
printf("Sum of the series: %d", sum);
return 0;
}
Exercise 10 :

#include <stdio.h>
int main() {
int n;
printf("Enter the number of rows: ");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
printf("# ");
}
printf("\n");
}
return 0;
}

You might also like