C

1.Hello World Program in c language

#include<stdio.h>
#include<conio.h>
void main()
{
printf(“Hello World!”);
}

 

 

 

 

 

2.Sum of n-Natural Number using “for loop”

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,sum=0;
printf(“enter the value of n”);
scanf(“%d”,&n);

for(i=0;i<=n;i++)
{
sum=sum+i;
}
printf(“sum is %d”,sum);
}

 

 

 

 

 

3.Sum of Integer Numbers

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf(“enter the value of a & b”);
scanf(“%d%d”,&a,&b);
c=a+b;
printf(“c=%d”,c);
getch();
}

4. Sum of Floating Point Number

#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c;
printf(“enter the value of a and b”);
scanf(“%f%f”,&a,&b);
c=a+b;
printf(“sum=%f”,c);
}

5. Entered character or integer is Alphabet or Not

#include<stdio.h>
#include<conio.h>
void main()
{
char c;
printf(“enter the value”);
scanf(“%c”,&c);

if((c>=’a’ && c<=’z’) || (c>=’A’ && c<=’Z’))
{
printf(“%c is a alphabet”,c );
}
else
{
printf(“%c is not a alphabet”,c);
}
}

6.How to Check Value of any Character

#include<stdio.h>
#include<conio.h>
void main()
{
char c;
printf(“Enter a character:”);
scanf(“%c”,&c);
printf(“ASCII value of %c=%d”,c,c);
}

7.Sum of n-integer Number

#include<stdio.h>
#include<conio.h>
void main()
{
int sum,i,n;
printf(“enter the value of n”);
scanf(“%d”,&n);
for(i=0;i<=n;i++)
sum=sum+i;
printf(“%d”,sum);
}

8.Counting integer number

#include<stdio.h>
#include<conio.h>
void main()
{
int n,count=0;
printf(“enter the number”);
scanf(“%d”,&n);

while(n!=0)
{
n=n/10;
count++;
}

printf(“%d”,count);
}

9.How to Check the “Quotient” and “Remainder” by Dividor and Dividend

#include<stdio.h>
#include<conio.h>
void main()
{

int divisor,dividend,remainder,quotient;

printf(“Enter the value of dividend”);
scanf(“%d”,&dividend);

printf(“Enter the value of divisor”);
scanf(“%d”,&divisor);

quotient=dividend/divisor;
remainder=dividend%divisor;

printf(“quotient=%d”,quotient);
printf(“remainder=%d”,remainder);
}

10.How to Calculate factorial of any Number

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,fact;
printf(“enter any number”);
scanf(“%d”,&n);

if(n<0)
{
printf(“factorial doesn’t exist”);
}

else
{

for(i=1;i<n;i++)
{
fact=fact*i;
}
printf(“factorial is %d”,fact,n);
}

11. Fibonacci Series

#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,t1=0,t2=1,next;
printf(“Enter any integer number”);
scanf(“%d”,&n);

printf(“Fibonacci series..”);

for(i=0;i<=n;i++)
{
printf(“%d”,t1);
next=t1+t2;
t1=t2;
t2=next;
} }

12.How to know the H.C.F of any given number

#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2,i,hcf;
printf(“enter the value of n1 and n2”);
scanf(“%d%d”,&n1,&n2);

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

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

hcf=i;
}
printf(“result of %d and %d is %d”,n1,n2,hcf);
}

13.Which is largest Number in between two number ( If-else Condition)

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf(“enter the value of a and b”);
scanf(“%d%d”,&a,&b);
if(a>b)
{
printf(“a is largest:%d”);
}
else
printf(“b is largest:%d”);
}

14. Check the given Number is Leap Year or Not.

#include<stdio.h>
#include<conio.h>
void main()
{
int year;
printf(“enter the year”);
scanf(“%d”,&year);

if(year%4==0)
{
if(year%100==0)
{
if(year%400==0)
printf(“%d is a leap year”,year);
else
printf(“%d is not a leap year”,year);
}
else
printf(“%d is a leap year”,year);
}
else
printf(“%d is not a leap year”,year);
getch();
}

15.Find out that the given number we entered is even or odd??

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf(“enter the value of n”);
scanf(“%d”,&n);

if(n/2==0)
{
printf(“number is even”);
}
else
{
printf(“number is odd”);
}
}

16. The Given integer we entered is Positive or Negative ??

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf(“enter the value of n”);
scanf(“%d”,&n);

if(n>0)
{
printf(“number is positive”);
}
else
{
printf(“number is negative”);
}
}

17. Prime Number or Not

#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,count=0;
printf(“Enter the number”);
scanf(“%d”,&num);

for(i=2;i<num;i++)
{
if(num%i==0)
{
count++;
break;
}
}
if(count==0)
{
printf(“this is a prime number”);
}
else
{
printf(“this is not a prime number”);
}
}

18.Character is Vowel or Consonant.

#include<stdio.h>
#include<conio.h>
void main()
{
char c,upper,lower;
printf(“enter the character”);
scanf(“%c”,&c);

upper=(c==’A’||c==’E’ ||c==’I’ ||c==’O’|| c==’U’);
lower=(c==’a’||c==’e’ ||c==’i’ ||c==’o’|| c==’u’);

if(upper||lower)
{
printf(“%c is vowel”,c);
}
else
{
printf(“%c is consonent”,c);
}
getch();

}

19.Elligible for Voting or Not

#include<stdio.h>
#include<conio.h>
void main()
{
int age;
printf(“enter the value of age”);
scanf(“%d”,&age);
if(age>18)
{
printf(“elligible”);
}
else
{
printf(“not elligible”);
}

}

20. Largest Number Among three Number

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf(“enter the value of a b c”);
scanf(“%d%d%d”,&a,&b,&c);

if(a>b && a>c)
{
printf(“a is largest”);
}
else
if(b>a && b>c)
{

printf(“%d is largest”);
}
else
{
printf(“c is largest”);
}
getch();

}

21. Size of Char, Int, Float

#include<stdio.h>
#include<conio.h>
void main()
{
int integerType;
float floatType;
double doubleType;
char charType;

printf(“size of int:%ld \n”,sizeof(integerType));
printf(“size of float:%ld \n”,sizeof(floatType));
printf(“size of doubleType:%ld \n”,sizeof(doubleType));
printf(“size of charType:%ld \n”,sizeof(charType));
}

22. Given Number is Prime or Not

#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,count=0;
printf(“Enter the number”);
scanf(“%d”,&num);

for(i=2;i<num;i++)
{
if(num%i==0)
{
count++;
break;
}
}
if(count==0)
{
printf(“this is a prime number”);
}
else
{
printf(“this is not a prime number”);
}
}

23.Multiple Arithmatic Operation Simultaneously

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,add,sub,mul;
printf(“Enter the Valueof a and b”);
scanf(“%d%d”,&a,&b);

add=a+b;
sub=a-b;
mul=a*b;

printf(“add=%d \n”,add);
printf(“sub=%d \n”,sub);
printf(“mul=%d \n”,mul);

}

24.Calculate the Length of String

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
char s[50];
printf(“Enter any name”);
scanf(“%c”,&s);

for(i=0; s[i] !=’\0′;i++)

printf(“length of %d”,s,i);

}

25.Addition of two matrix

#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,a[3][3],b[3][3],sum[3][3];

printf(“enter the first matrix”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf(“%d”,&a[i][j]);
}

printf(“enter the second matrix”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf(“%d”,&b[i][j]);
}

printf(“sum of both the matrix”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
sum[i][j]=a[i][j]+b[i][j];
}
}

printf(“enter the resultant matrix\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf(“%d\n”,sum[i][j]);
}
printf(“\n”);

}

26.Multiplication of Two Matrix

#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,a[3][3],b[3][3],mul[3][3];

printf(“enter the first matrix”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf(“%d”,&a[i][j]);
}

printf(“enter the second matrix”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf(“%d”,&b[i][j]);
}

printf(“sum of both the matrix\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
mul[i][j]=a[i][j]*b[i][j];
}
}

printf(“enter the resultant matrix\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf(“%d\n”,mul[i][j]);
}
printf(“\n”);

}

27.Transpose of a Matrix

#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,a[3][3],t[3][3];

printf(“Enter the matrix”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf(“%d”,&a[i][j]);
}
printf(“transpose”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
t[j][i]=a[i][j];
}

printf(“Transpose of a Matrix\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf(“%d”,t[i][j]);
}
getch();
}

28.Table of any integer number

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
printf(“enter any number @ n”);
scanf(“%d”,&n);

for(i=1;i<=10;i++)
{
printf(“Result is %d*%d=%d \n”,n,i,n*i);
}

}

29.Swapping Program

#include<stdio.h>
#include<conio.h>
void main()
{
int firstnumber, secondnumber,temp;

printf(“Enter the firstnumber”);
scanf(“%d”,&firstnumber);
printf(“Enter the secondnumber”);
scanf(“%d”,&secondnumber);

temp=firstnumber;
firstnumber=secondnumber;
secondnumber=temp;

printf(“After swapping, firstnumber=%d \n”,firstnumber);
printf(“After swapping, secondnumber=%d \n”,secondnumber);
}

30. Calculator Using Switch Case

#include<stdio.h>
#include<conio.h>
int main()
{
int n1,n2;
char oper;

printf(“enter a operator +,-,*…”);
scanf(“%c”,&oper);

printf(“enter the n1 & n2”);
scanf(“%d%d”,&n1,&n2);

switch(oper)
{

case ‘+’ :
printf(“%d+%d=%d”,n1,n2,n1+n2);
break;

case ‘-‘ :
printf(“%d-%d=%d”,n1,n2,n1-n2);
break;

case ‘*’ :
printf(“%d*%d=%d”,n1,n2,n1*n2);
break;

default:
printf(“Not Present”);
break;
}
}

31.Days Selection using Switch Case

#include<stdio.h>
#include<conio.h>
int main()
{
int n;
printf(“enter the value of n”);
scanf(“%d”,&n);

switch(n)
{
case 1:
printf(“Sunday”);
break;

case 2:
printf(“Monday”);
break;

case 3:
printf(“Tuesday”);
break;

case 4:
printf(“Wednesday”);
break;

case 5:
printf(“Thrusday”);
break;

case 6:
printf(“Friday”);
break;

case 7:
printf(“Saturday”);
break;

default:
printf(“Not Here”);
}

}

Leave a Reply

Your email address will not be published. Required fields are marked *