0% found this document useful (0 votes)
2 views16 pages

Notes

The document contains multiple C programming examples covering various topics such as declaring variables, mathematical operations, control structures, and algorithms for tasks like calculating compound interest, checking for prime numbers, and finding GCD and LCM. Each section demonstrates specific programming concepts through simple code snippets. Overall, it serves as a practical guide for basic C programming techniques.

Uploaded by

tarunvs1234
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)
2 views16 pages

Notes

The document contains multiple C programming examples covering various topics such as declaring variables, mathematical operations, control structures, and algorithms for tasks like calculating compound interest, checking for prime numbers, and finding GCD and LCM. Each section demonstrates specific programming concepts through simple code snippets. Overall, it serves as a practical guide for basic C programming techniques.

Uploaded by

tarunvs1234
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

//declaring char//

#include<stdio.h>

int main()

char a;

printf("enter the value of a=\n");

scanf("%C",&a);

printf("a=%c\n",a);

return 0;

//declaring data type//

#include<stdio.h>

int main()

int a=4;

float b=0.5;

char c='a';

printf("enter the value of data type\n");

printf("a=%d\tb=%f\tc=%c",a,b,c);

return 0;

//#include<stdio.h>

int main()

int a=1,b=8;

printf("before swapping a=%d,b=%d\n",a,b);

a=a^b;

b=a^b;

a=a^b;
printf("after swapping a=%d,b=%d\n",a,b);

//compound interest//

#include<stdio.h>

#include<math.h>

int main()

double principal=2300;

double rate=7;

double time=4;

double amount=principal*((pow((1+rate/100),time)));

double ci =amount-principal;

printf("compound intrest is %lf",ci);

return 0;

//mathematical operations//

#include<stdio.h>

int main()

int a=3,b=4,c;

c=a+b;

printf("a+b=%d\n",c);

c=a-b;

printf("a-b=%d\n",c);

c=a*b;

printf("a*b=%d\n",c);

c=a/b;

printf("a/b=%d\n",c);
return 0;

//ovel//

#include<stdio.h>

int main()

char ch;

printf("Enter the character:");

scanf(" %c",&ch);

if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='u')

printf("Enterd character is oval=%c\n",ch);

else

printf("Enterd character is not a oval=%c\n",ch);

return 0;

}
//using switch case//

#include<stdio.h>

void sum(int a, int b)

printf("Sum = %d\n", a + b);

void diff(int a, int b)

printf("Difference = %d\n", a - b);

void mul(int a, int b)

printf("Multiplication = %d\n", a * b);

void mod(int a, int b)

if (b != 0) {

printf("Modulus = %d\n", a % b);

} else {

printf("Error: Division by zero is not allowed for modulus.\n");

void divd(int a, int b)

if (b != 0)

{
printf("Division = %d\n", a / b);

} else

printf("Error: Division by zero is not allowed.\n");

int main()

int a = 5, b = 7, choice;

char ch;

do {

printf("\nEnter your choice:\n");

printf("1. Addition\t2. Subtraction\n3. Multiplication\t4. Modulus\n5. Division\n");

printf("Choice: ");

scanf("%d", &choice);

switch (choice)

case 1:

sum(a, b);

break;

case 2:

diff(a, b);

break;

case 3:

mul(a, b);

break;

case 4:

mod(a, b);
break;

case 5:

divd(a, b);

break;

default:

printf("Invalid Input\n");

printf("Do you want to continue? (y/n): ");

scanf(" %c", &ch);

} while (ch == 'y' || ch == 'Y');

return 0;

}
//using if else statement//

#include<stdio.h>

int main()

int a=19,b=325,c=34;

if(a>b)

if(a>c)

printf("a=%d is greater:\n",a);

else

printf("c=%d is greater:\n",c);

else

if(b>c)

printf("b=%d is greater:\n",b);

else

printf("c=%d is greater:\n",c);

return 0;

}
//prime or not//

#include<stdbool.h>

#include<stdio.h>

int main()

int n=91;

int cnt=0;

if(n<=1)

printf("%d is not prime\n",n);

else

for(int i=1;i<=n;i++)

if(n%i==0)

cnt++;

if(cnt>2)

printf("%d is not a prime\n",n);

else

printf("%d is prime\n",n);

return 0;

}
//reverse//

#include <stdio.h>

int main()

int num, reversedNum = 0, remainder;

// Ask user for input

printf("Enter an integer: ");

scanf("%d", &num);

// Reverse the number

while (num != 0)

remainder = num % 10; // Get the last digit

reversedNum = reversedNum * 10 + remainder; // Add it to reversed number

num /= 10; // Remove the last digit from num

// Output the reversed number

printf("Reversed number: %d\n", reversedNum);

return 0;

}
//leap year//

#include <stdio.h>

void leap_year(int year)

if (year % 400 == 0)

printf("%d is a leap year.\n", year);

else if (year % 100 == 0)

printf("%d is not a leap year.\n", year);

else if (year % 4 == 0)

printf("%d is a leap year.\n", year);

else

printf("%d is not a leap year.\n", year);

int main()

leap_year(2000);

leap_year(2002);

leap_year(2008);

return 0;

}
//lcm//

#include <stdio.h>

int main() {

int n1, n2, max, lcm;

printf("Enter two positive integers: ");

scanf("%d %d", &n1, &n2);

max = (n1 > n2) ? n1 : n2;

lcm = max;

while ((lcm % n1 != 0) || (lcm % n2 != 0)) {

lcm += max;

printf("The LCM of %d and %d is %d.", n1, n2, lcm);

return 0;

}
//gcd//

#include<stdio.h>

int main()

int n1 , n2 , gcd = 1;

printf("enter the value od n1 and n2\n");

scanf("%d%d",&n1,&n2);

for(int i = 1; i <= n1 || i <= n2; i++) {

if(n1 % i == 0 && n2 % i == 0)

gcd = i;

printf("The GCD of %d and %d is: %d", n1, n2, gcd);

return 0;

}
// binary to decimal//

#include <stdio.h>

int main()

int n, i = 0, binary[32] = {0};

printf("Enter a decimal number: ");

scanf("%d", &n);

while (n > 0)

binary[i] = n % 2;

n = n / 2;

i++;

printf("Binary representation: ");

for (int j = i - 1; j >= 0; j--)

printf("%d", binary[j]);

printf("\n");

return 0;

}
//armstrong//

#include<stdio.h>

#include<math.h>

int main()

int num=153,sum=0,rem;

int temp=num;

while(num!=0)

rem=num%10;

sum=sum+pow(rem,3);

num=num/10;

if(temp==sum)

printf("armstrong number\n");

else

printf("not armstrong number\n");

}
//factorial//

#include <stdio.h>

void factorial_iteration(int N)

unsigned long long int ans = 1;

for (int i = 1; i <= N; i++) {

ans = ans * i;

printf("Factorial of %d is %lld\n", N, ans);

int factorial(int N)

if (N == 0)

return 1;

return N * factorial(N - 1);

int main()

int n;

factorial_iteration(n);

printf("enter the number\n");

scanf("%d",&n);

printf("Factorial of %d using recursion:%d\n", n,factorial(n));

return 0;

}
//bitwise//

#include<stdio.h>

int main()

int a,b;

printf("enter two number\n");

scanf("%d",&a,&b);

printf("a&b=%d\n",a&b);

printf("a|b=%d\n",a|b);

printf("a^b=%d\n",a^b);

printf("~a=%d\n",~a);

printf("a<<1=%d\n",a<<1);

printf("a>>1=%d\n",a>>1);

return 0;

You might also like