NAME: RUPAM MALLICK
C PROGRAM
ENGLISH
SUBJECT: CYOGA (MATH)
ASSIGNMENT
PROGRAMMING (1)
REGISTRATION NO : 233002410591
DEPARTMENT NAME: BSC (IT) CYBER SECURITY
YEAR: 1st Year
SEMESTER: 1
DATE OF SUBMISSION:
1. PRINT HELLO WORLD
#include <stdio.h>
int main() {
printf("Hello world");
return 0;
}
OUT PUT :
Hello world
2. SUM OF TWO NUMBER
#include <stdio.h>
int main() {
int a=2,b=3,s=0;
s=a+b;
printf("the sum of two number is %d",s);
return 0;
}
OUT PUT :
the sum of two number is 5
3. Sum of first n natural numbers
#include <stdio.h>
int main() {
int a,b,n;
printf("how much number of sum you want :");
scanf("%d",&n);
for (a=1;a<=n;a++)
{
b=b+a;
}
printf("the sum of n number is %d",b);
return 0;
}
OUT PUT :
how much number of sum you want :5
the sum of n number is 15
4. SUM OF A NUMBER UP TO AN EVEN NUMBER
#include <stdio.h>
int main() {
int a,b,n,g;
printf("How much number of sum you want :");
scanf("%d",&n);
for (a=1;a<=n;a++)
{
g=a;
if (g%2==0)
{
b=b+a;
}
printf("The sum of n number is %d",b);
return 0;
}
OUT PUT :
How much number of sum you want :10
The sum of n number is 30
5. SUM OF ODD NUMBERS
#include <stdio.h>
int main() {
int a,b,n,g;
printf("how much number of sum you want :");
scanf("%d",&n);
for (a=1;a<=n;a++)
{
g=a;
if (g%2==!0)
{
b=b+a;
}
printf("the sum of n number is %d",b);
return 0;
}
OUT PUT:
how much number of sum you want :10
the sum of n number is 25
6. EVALUATION OF THE PROVIDED FACTORIAL NUMBER
#include <stdio.h>
int main() {
int a,b=1,n,g;
printf("enter your number :");
scanf("%d",&n);
for (a=1;a<=n;a++)
{
b=b*a;
}
printf("the factoryeal of n number is %d",b);
return 0;
}
OUT PUT :
Enter your number 4
the factoryeal of n number is 24
7. sum of digits of a number in c
#include <stdio.h>
int main() {
int num, digit, sum = 0;
printf("Enter a number: ");
scanf("%d", &num);
while (num != 0) {
digit = num % 10;
sum += digit;
num /= 10;
}
printf("Sum of digits: %d\n", sum);
return 0;
}
OUT PUT :
Enter a number: 234
Sum of digits: 9
[Link] OF A TRIANGLE
#include <stdio.h>
int main() {
float base, height, area;
printf("Enter the base of the triangle: ");
scanf("%f", &base);
printf("Enter the height of the triangle: ");
scanf("%f", &height);
area = 0.5 * base * height;
printf("Area of the triangle: %.2f\n", area);
return 0;
}
OUT PUT:
Enter the base of the triangle: 4
Enter the height of the triangle: 5
Area of the triangle: 10.00