0% found this document useful (0 votes)
34 views3 pages

Basic C Programs For Beginners

Praogram

Uploaded by

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

Basic C Programs For Beginners

Praogram

Uploaded by

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

Basic C Programs for Beginners

1. Hello World Program


#include <stdio.h>

int main() {
printf("Hello, World!\n");
return 0;
}

2. Program to Add Two Numbers


#include <stdio.h>

int main() {
int num1, num2, sum;

printf("Enter two numbers: ");


scanf("%d %d", &num1, &num2);

sum = num1 + num2;


printf("Sum: %d\n", sum);

return 0;
}

3. Program to Check Even or Odd


#include <stdio.h>

int main() {
int num;

printf("Enter an integer: ");


scanf("%d", &num);

if(num % 2 == 0)
printf("%d is even.\n", num);
else
printf("%d is odd.\n", num);
return 0;
}

4. Program to Find the Largest of Three Numbers


#include <stdio.h>

int main() {
int num1, num2, num3;

printf("Enter three numbers: ");


scanf("%d %d %d", &num1, &num2, &num3);

if(num1 >= num2 && num1 >= num3)


printf("Largest number is: %d\n", num1);
else if(num2 >= num1 && num2 >= num3)
printf("Largest number is: %d\n", num2);
else
printf("Largest number is: %d\n", num3);

return 0;
}

5. Program to Calculate the Factorial of a Number


#include <stdio.h>

int main() {
int num, i;
unsigned long long factorial = 1;

printf("Enter an integer: ");


scanf("%d", &num);

if(num < 0)
printf("Factorial of a negative number doesn't exist.\n");
else {
for(i = 1; i <= num; ++i) {
factorial *= i;
}
printf("Factorial of %d = %llu\n", num, factorial);
}
return 0;
}

6. Program to Print the Fibonacci Sequence


#include <stdio.h>

int main() {
int n, t1 = 0, t2 = 1, nextTerm;

printf("Enter the number of terms: ");


scanf("%d", &n);

printf("Fibonacci Series: %d, %d", t1, t2);

for(int i = 1; i <= n-2; ++i) {


nextTerm = t1 + t2;
printf(", %d", nextTerm);
t1 = t2;
t2 = nextTerm;
}
printf("\n");

return 0;
}

You might also like