Professional Documents
Culture Documents
C Prog Up1
C Prog Up1
Output:
Om Sri Sai Ram
Process returned 0 (0x0) execution time : 0.125 s
Area of circle:
Enter the radius:5
Area of circle:75
Area of triangle:
Enter the height:4
Enter the base:6
Area of triangle: 12.000000
Process returned 0 (0x0) execution time : 7.891 s
Enter a number:
81
The number 81 is divisible by 3
Process returned 0 (0x0) execution time : 21.979 s
getch();
}
Output:
Enter a number:
0
The given number 0 is zero
Process returned 0 (0x0) execution time : 2.969 s
Enter a number:
5
The given number 5 is not zero
Process returned 0 (0x0) execution time : 2.005 s
Enter a number:
46
The number 46 is even
Process returned 0 (0x0) execution time : 15.891 s
Output:
Enter a number:
5
Prime
Process returned 0 (0x0) execution time : 4.047 s
Enter a number:
81
Not Prime
Process returned 0 (0x0) execution time : 2.469 s
Output:
Calculation of Simple Interest
Enter the Principal amount: 55
Enter the number of years: 4
Enter the rate of interest: 5
The Simple Interest: 11
Process returned 0 (0x0) execution time : 9.391 s
Output:
Calculation of Sum of numbers
Enter the number of inputs to be added:5
Enter the numbers to be added:
76
456
34
56
67
76+456+34+56+67+
The sum is: 689
Process returned 0 (0x0) execution time : 15.117 s
Output:
Enter number: 45
Total numbers: 6
Enter number :45
Enter number :76
Enter number :87
Enter number :23
Enter number :098
Enter number :67
Largest=98
Process returned 0 (0x0) execution time : 12.420 s
Enter 3 numbers:
98
56
72
98 is the largest
56 is the smallest
Output:
Enter a number:7
1234567
Sum of the natural numbers till 7 is 8
Process returned 0 (0x0) execution time : 2.125 s
Output:
Enter a number:
25
1 * 25= 25
2 * 25= 50
3 * 25= 75
4 * 25= 100
5 * 25= 125
6 * 25= 150
7 * 25= 175
8 * 25= 200
9 * 25= 225
10 * 25= 250
Output:
Enter a number:153
It is a armstrong number.
Process returned 0 (0x0) execution time : 41.856 s
Enter a number:53
It is not a armstrong number.
Process returned 0 (0x0) execution time : 2.500 s
Output:
Enter a number:656
Enter a number:766
The number 766 is not a palindrome
Output:
Enter a number:6
Enter a number:36
Output:
Enter the number:
27
81
The GCD of the given numbers 27 and 81 is 27
Process returned 0 (0x0) execution time : 8.047 s
Output:
Enter a number:10
Fibonacci series:1 1 2 3 5 8 13 21 34 55
Process returned 0 (0x0) execution time : 3.531 s
#include<stdio.h>
int main()
{
int var1,var2,temp,a,b;
printf("Enter two numbers:");
scanf("%d %d",&var1,&var2);
printf(" Before exchange \n Variable 1: %d \n Variable 2: %d",var1,var2);
temp=var1;
var1=var2;
var2=temp;
printf("\n After exchange \n Variable 1: %d \n Variable 2: %d",var1,var2);
return 0;
}
Output:
Enter your marks : enter -1 at the end
95
96
99
100
98
-1
The average is 97.599998
Process returned 0 (0x0) execution time : 22.016 s
Output:
Enter a number:
5
Enter the exponent value till it should get calculated:8
5^1=5
5^2=25
5^3=125
5^4=625
5^5=3125
5^6=15625
5^7=78125
5^8=390625
Process returned 0 (0x0) execution time : 11.641 s
printf("\n");
}
getch();
}
Output:
Enter the number of rows:5
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Output:
Enter the number of rows:4
1
111
11111
1111111
}
getch();
}
Output:
Enter the number of rows:6
*
***
*****
*******
*********
***********
Process returned 0 (0x0) execution time : 2.516 s
case 2:
{
printf("\nArea of circle: ");
printf("\nEnter the radius:");
scanf("%d",&rad);
printf("Area of circle:%d",pi*rad*rad);
break;
}
case 3:
{
printf("\nArea of triangle: ");
printf("\nEnter the height:");
scanf("%d",&ht);
printf("\nEnter the base:");
scanf("%d",&base);
printf("Area of triangle: %f",a*base*ht);
break;
}
default:
printf("Invalid choice");
}
return 0;
}
Output:
Enter the figure for which you need to find area:
1.Square
2.Circle
3.Triangle
1
Area of square:
Enter the length of side:5
Area of square:25
2
Area of circle:
Enter the radius:6
Area of circle:108
3
Area of triangle:
Enter the height:5
Enter the base:6
Area of triangle: 15.000000
Process returned 0 (0x0) execution time : 78.184 s
Press any key to continue
.
29. Find the electricity bill of a month
#include<stdio.h>
int main()
{
int met,x,y,a,b;
printf("Enter the meter readings:");
scanf("%d",&met);
if(met>0&&met<500)
printf("The rate is: $20");
else if(met>501&&met<1000)
{
x=met-500;
y=20+(x*0.03);
printf("The rate is: $%d",y);
}
else
{
a=met-1000;
b=35+(a*0.02);
printf("The rate is: $%d",b);
}
return 0;
}
Output:
Enter the meter readings:499
The rate is: $20
Process returned 0 (0x0) execution time : 5.994 s
30. Find GCD using Euclids Algorithm
Output:
Enter two numbers:
98
56
The GCD of the given numbers 98 and 56 is 14
32.Swap the given two numbers
// Program to swap the given two numbers//
#include<stdio.h>
void main()
{
int var1,var2;
clrscr();
printf("Enter two numbers:");
scanf("%d %d",&var1,&var2);
printf(" Before exchange \n Variable 1: %d \n Variable 2: %d",var1,var2);
exchange(var1,var2);
getch();
}
exchange(int a,int b)
{
int temp;
temp=a;
a=b;
b=temp;
printf("\n After exchange \n Variable 1: %d \n Variable 2: %d",a,b);
}
Output:
Enter two numbers:
56
87
Before exchange
Variable 1: 56
Variable 2: 87
After exchange
Variable 1: 87
Variable 2: 56
Process returned 0 (0x0) execution time : 3.891 s