C Record
C Record
C Record
com
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Hi! Welcome to C!!!");
getch();
}
1
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c; // Variable declaration
clrscr();
2
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
float cm, mts;
clrscr();
mts = cm / 100;
printf("Given distance in Meters: %.2f mts",mts);
getch();
}
3
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
int a = 5, b = 10, c, d;
clrscr();
c = a++;
d = ++b;
printf("Post increment result: %d\n",c);
printf("Pre increment result: %d\n",d);
c = a-- + --b;
printf("Finally C = %d",c);
getch();
}
4
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
int num;
clrscr();
if(num % 2 == 0)
printf("\n%d is EVEN number");
else
printf("\n%d is ODD number");
getch();
}
5
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
getch();
}
6
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
int num1, num2, temp;
clrscr();
temp = num1;
num1 = num2;
num2 = temp;
getch();
}
7
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
getch();
}
8
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c, root1,root2,temp, real, imag;
clrscr();
printf("\nRoot1 = %.2f",root1);
printf("\nRoot2 = %.2f",root2);
}
else{
if(temp == 0)
{
printf("\nRoots are real:\n");
root1 = root2 = -b/(2*a);
printf("\nRoot1 = %.2f",root1);
printf("\nRoot2 = %.2f",root2);
}
else
{
real = -b / (2*a);
imag = sqrt(-temp) / (2*a);
printf("\nRoots are imaginary:\n");
printf("Root1 = %.2f + %.2fi",real,imag);
printf("\nRoot2 = %.2f - %.2fi",real,imag);
}
}
getch();
}
9
www.btechsmartclass.com
10
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
#define PI 3.14
void main()
{
float radius,area,circumference;
clrscr();
area = PI*(radius*radius);
circumference = 2 * PI * radius;
printf("\nArea = %.2f",area);
printf("\nCircumference = %.2f",circumference);
getch();
}
11
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
float base,height,area;
clrscr();
getch();
}
12
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
int num,fact=1,i;
clrscr();
printf("\nFactorial of %d is %d",num,fact);
getch();
}
13
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
int num,count=0,i;
clrscr();
getch();
}
14
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
int num,count,i,value;
clrscr();
15
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
int count = 1;
clrscr();
getch();
}
16
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
int a=0,b=1,c,n,count = 3;
clrscr();
getch();
}
17
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
int num,reverse=0,remainder;
clrscr();
while(num>0)
{
remainder = num % 10;
reverse = reverse * 10 + remainder;
num = num / 10;
}
printf("\nReverse of given number is %d",reverse);
getch();
}
18
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
int num,reverse=0,remainder,temp;
clrscr();
while(num>0)
{
remainder = num % 10;
reverse = reverse * 10 + remainder;
num = num / 10;
}
if(temp == reverse)
printf("\nGiven number is PALINDROME!!!");
else
printf("\nGiven number is NOT POLINDROME!!!");
getch();
}
19
www.btechsmartclass.com
19. Write a C program to test whether given number is ARMSTRONG number or NOT.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int num,sum=0,remainder,temp;
clrscr();
while(num>0){
remainder = num % 10;
sum = sum + pow(remainder,3);
num = num / 10;
}
if(temp == sum)
printf("\nGiven number is ARMSTRONG!!!");
else
printf("\nGiven number is NOT ARMSTRONG!!!");
getch();
}
20
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
int num1,num2,result;
int addition(int,int);
clrscr();
result = addition(num1,num2);
getch();
}
21
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
int num1,num2,result;
int addition(int,int);
int subtraction(int,int);
int multiplication(int,int);
int division(int,int);
int modulo(int,int);
clrscr();
printf("\n%d + %d = %d",num1,num2,addition(num1,num2));
printf("\n%d - %d = %d",num1,num2,subtraction(num1,num2));
printf("\n%d * %d = %d",num1,num2,multiplication(num1,num2));
printf("\n%d / %d = %d (float value is type casted!)",num1,num2,division(num1,num2));
printf("\n%d %% %d = %d",num1,num2,modulo(num1,num2));
getch();
}
22
www.btechsmartclass.com
23
www.btechsmartclass.com
22. Write a C program to find SUM of individual digits of given integer number.
#include<stdio.h>
#include<conio.h>
void main()
{
int num,sum=0,remainder;
clrscr();
while(num>0)
{
remainder = num % 10;
sum = sum + remainder;
num = num / 10;
}
printf("\nSUM of individual digits of given number is %d",sum);
getch();
}
24
www.btechsmartclass.com
23. Write a C program to perform all Arithmetic operations using switch statement.
#include<stdio.h>
#include<conio.h>
void main()
{
int num1,num2;
char choice;
clrscr();
switch(choice)
{
case '+': printf("\n%d + %d = %d",num1,num2,num1+num2); break;
case '-': printf("\n%d - %d = %d",num1,num2,num1-num2); break;
case '*': printf("\n%d * %d = %d",num1,num2,num1*num2); break;
case '/': if(num2==0)
printf("\nDivision not posible!!!");
else
printf("\n%d / %d = %d",num1, num2, num1/num2);
break;
case '%': printf("\n%d %% %d = %d",num1,num2,num1%num2); break;
default: printf("\nWrong input!!!");
}
getch();
}
25
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
void main()
{
int num1,num2,temp=1,gcd;
clrscr();
getch();
}
26
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int x,i=0,n=0;
float sum=0;
long fact(int);
clrscr();
while(i<=10)
{
sum = sum+(pow(-1,n)*pow(x,i)/fact(i));
i=i+2;
n++;
}
printf("\nSUM = %ld",sum);
getch();
}
long fact(int a)
{
long f=1;
while(a!=0){
f = f*a;
a--;
}
return f;
}
27
www.btechsmartclass.com
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float u,t,s,a;
clrscr();
s = (u*t) + (0.5)*a*pow(t,2);
printf("\nResult = %.2f",s);
getch();
}
28