C PROGRAMMES - SET-1 - GECR GEEK - Updated
C PROGRAMMES - SET-1 - GECR GEEK - Updated
www.gecrgeek.blogspot.com
C Programmes Set -1
All C programmes written here are working and tested with outputs mentioned. Check out
them all!
6. A program which accepts a character from the keyboard and displays it with use of getchar() and
putchar().
Page 1
www.gecrgeek.blogspot.com
CPU Programmes Set-1
www.gecrgeek.blogspot.com
10. C program to check whether a character is Capital, Small case letter, digit or special symbol.
13. C program to multiply and divide a given number by 2 using bit-wise operators.
int main()
{
printf("Hello world\n");
return 0;
}
Output:
Hello world
int main()
{
int first, second, add, subtract, multiply, modulo;
float divide;
printf("Sum = %d\n",add);
printf("Difference = %d\n",subtract);
printf("Multiplication = %d\n",multiply);
printf("Modulo = %d\n",modulo);
printf("Division = %.2f\n",divide);
Page 2
www.gecrgeek.blogspot.com
CPU Programmes Set-1
www.gecrgeek.blogspot.com
return 0;
}
Output:
Enter two integers
15 4
Sum = 19
Difference = 11
Multiplication = 60
Modulo = 3
Division = 3.75
s = (a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of triangle is: %.3f",area);
return 0;
output:
Enter size of each sides of the triangle: 2 4 5
Area of triangle is: 3.800
#include<stdio.h>int main()
Output
Page 3
www.gecrgeek.blogspot.com
CPU Programmes Set-1
www.gecrgeek.blogspot.com
int main()
{
int fahr,cel,choice;
switch(choice)
{
case 1:
printf("Enter fahrenheit value\n");
scanf("%d",&fahr);
cel=(fahr-32)*5/9;
printf("Celsius of %d degrees fahrenheit is %d degrees
celsius\n\n",fahr,cel);
case 2:
printf("Enter celsius value\n");
scanf("%d",&cel);
fahr=(1.8*cel) + 32;
printf("Fahrenheit of %d degrees Celsius is %d degrees
fahrenheit\n\n",cel,fahr);
}
}
Output:
6. A program which accepts a character from the keyboard and displays it with use of
getchar() and putchar()
#include<stdio.h>
#include<conio.h>
void main()
{
char x;
clrscr();
x= getchar();
putchar(x);
getch();
}
Output:
D
D
Page 4
www.gecrgeek.blogspot.com
CPU Programmes Set-1
www.gecrgeek.blogspot.com
int main()
{
int x, y, temp;
temp = x;
x = y;
y = temp;
return 0;
}
Output:
Enter the value of x and y
24
Before Swapping
x=2
y=4
After Swapping
x=4
y=2
#include <stdio.h>
int main(){
float a, b, c;
printf("Enter three numbers: ");
scanf("%f %f %f", &a, &b, &c);
if(a>=b && a>=c)
printf("Largest number = %.2f", a);
if(b>=a && b>=c)
printf("Largest number = %.2f", b);
if(c>=a && c>=b)
printf("Largest number = %.2f", c);
return 0;
}
Output:
Enter three numbers:
2 4 99
Largest number = 99.00
Page 5
www.gecrgeek.blogspot.com
CPU Programmes Set-1
www.gecrgeek.blogspot.com
#include<stdlib.h>
void main()
{
int ch;
float a,b,res;
clrscr();
printf(“Enter two numbers:”);
scanf(“%f%f”,&a,&b);
printf(“\nMenu\n1.Addition \n2.Subtraction \n3.Multiplication \n4.Division
\n5.Modulo”);
printf(“\nEnter your choice:”);
scanf(“%d”,&ch);
switch(ch)
{
case 1: res=a+b;
break;
case 2: res=a-b;
break;
case 3: res=a*b;
break;
case 4: res=a/b;
break;
case 5: res=a%b
break;
default: printf(“Dude,Wrong choice!!\nPress any key…”);
getch();
exit(0);
}
printf(“\nResult=%f”,res);
getch();
}
Output:
Enter two numbers: 6 7
Menu
1. Addition
2.Subtraction
3.Multiplication
4.Division
5.Modulo
Enter your choice: 4
Result= 0.857143
10. C program to check whether a character is Capital, Small case letter, digit or special
symbol
#include <stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("Enter one character\n");
scanf("%c", &ch);
Page 6
www.gecrgeek.blogspot.com
CPU Programmes Set-1
www.gecrgeek.blogspot.com
if ((ch>='0')&&(ch<='9'))
printf("The character %c is digit\n",ch);
else if ((ch>='a')&&(ch<='z'))
printf("The character %c is Lower case\n",ch);
else if ((ch>='A')&&(ch<='Z'))
printf("The character %c is Upper case\n",ch);
else
printf("The character %c is other symbol\n",ch);
getch();
}
Output 1:
Enter one character
8
The character is digit
Output 2:
Enter one character
p
The character is Lower case
#include <stdio.h>
void main()
{
int i, num, sum = 0;
sum = sum + i;
Output:
1300
Page 7
www.gecrgeek.blogspot.com
CPU Programmes Set-1
www.gecrgeek.blogspot.com
max=(x>y)? x:y ;
min=(x<y)? x:y;
Output:
Give two integer numbers
27
Maximum of 2 and 7 is = 7
Minimum of 2 and 7 is = 2
13. C program to multiply and divide a given number by 2 using bit-wise operators
#include <stdio.h>
#include<conio.h>
void main()
{
int x;
int mul,div;
clrscr();
printf("Multiplication of %d by 2 = %d\n",x,mul);
printf("Division of %d by 2 = %d\n",x,div);
getch();
}
Output:
Give one integer number
6
Multiplication of 6 by 2 = 12
Division of 6 by 2 = 3
All C programmes written here are working and tested. Check out them all!
Stay Amazed, Stay Geeky,
Jay Akbari (Pixmercy)
Page 8
www.gecrgeek.blogspot.com