C Programming
C Programming
Program:
#include<stdio.h>
void main(){
Output :
Aim: Write a program in c to calculate the area of circle.
Program:
#include<stdio.h>
int main(){
Output :
Aim: Write a program in c to calculate simple interest.
Program:
#include<stdio.h>
int main(){
float r,s;
int p,t;
Output :
Aim: Write a program in c to find if a given year is leap year or not.
Program:
#include<stdio.h>
int main(){
int year;
Program :
#include<stdio.h>
int main(){
float kg = 0.45359237;
float p ;
Output :
2. Convert distance from miles to kilometer.
Program :
#include<stdio.h>
int main(){
float km = 1.609344;
float m ;
Output :
3. Temperature from degree Fahrenheit to degree Celsius.
Program :
#include<stdio.h>
int main(){
float f,c;
c=((f-32)*5)/9;
Output :
Aim: Write a program in c to calculate the bill from the no
Of units consume.
Program :
#include<stdio.h>
int main(){
float unit ;
Output :
Aim: Write a program in c to find the roots of a Quadratic
equation.
Program :
#include <stdio.h>
#include <math.h>
int main(){
float a, b, c;
float root1, root2, imaginary;
float discriminant;
discriminant = (b * b) - (4 * a * c);
printf("Two distinct and real roots exists: %.2f and %.2f", root1, root2);
}
else if(discriminant == 0){
root1 = root2 = -b / (2 * a);
printf("Two equal and real roots exists: %.2f and %.2f", root1, root2);
}
else if(discriminant < 0){
root1 = root2 = -b / (2 * a);
imaginary = sqrt(-discriminant) / (2 * a);
printf("Two distinct complex roots exists: %.2f + i%.2f and %.2f - i%.2f",
root1, imaginary, root2, imaginary);
}
}
Output :
Aim: Write a program in c to find the tallest of 3 friends.
Program :
#include<stdio.h>
#include<string.h>
int main(){
char n1[10],n2[10],n3[10];
float h1,h2,h3,t;
Program:
#include<stdio.h>
int main(){
int month ;
case 1:
printf("\n January ");
break;
case 2:
printf("\n February ");
break;
case 3:
printf("\n March ");
break;
case 4:
printf("\n April ");
break;
case 5:
printf("\n May ");
break;
case 6:
printf("\n June ");
break;
case 7:
printf("\n July ");
break;
case 8:
printf("\n Augest ");
break;
case 9:
printf("\n September ");
break;
case 10:
printf("\n October ");
break;
case 11:
printf("\n November ");
break;
case 12:
printf("\n December ");
break;
default:
printf("\n Invalid Month Number Please re-enter");
}
}
Output :
Aim: Write a program in c to display the table of a number using loops.
Program :
#include<stdio.h>
int main(){
int n,i;
Output :
Aim: Write a program in c to swaps two number using function.
Program:
#include<stdio.h>
int swap(int x,int y){
int temp;
temp = x ;
x=y;
y = temp ;
void main(){
int a,b ;
Output :
Aim : Write a program in c to find it a number is prime or not.
Program :
#include<stdio.h>
int main(){
int num,flag,i;
if(num==0 || num==1){
flag = 1;
}
for(i=2; i<=num/2; i++){
if( num % i == 0 ){
flag = 1;
break;
}
}
if(flag == 1){
printf("\n%d is Not a prime Number.",num);
}
else{
printf("\n%d is a Prime Number. ",num);
}
}
Output :
Aim : Write a program in c to generate a pyramid of stars.
Program :
#include<stdio.h>
int main(){
int n,i,j,s,k,l,S;
Output :
Aim: Write a program in c to find if a sequence is Palindrone or not.
Program :
#include<stdio.h>
int main(){
int num,temp,rem,rev=0;
while(temp>0){
rem = temp % 10 ;
rev = (rev * 10) + rem ;
temp = temp / 10 ;
}
if(num == rev){
printf("\n%d is a Palindrone Number.",num);
}
else{
printf("\n%d is Not a Palindrone Number.",num);
}
}
Output :
Aim: Write a program in c to create a calculator that can perform basic
arithmetic operation.
Program :
#include<stdio.h>
int add(int a,int b){
int c;
c=a+b;
return c;
}
int sub(int a, int b){
int c;
c=a-b;
return c;
}
int mult(int a, int b){
int c;
c=a*b;
return c;
}
int div(int a, int b){
int c;
c=a/b;
return c;
}
int main(){
int a,b,ch;
printf("Calculator :---\n\t 1. Addition\n\t 2. Subtraction\n\t 3.
Multiplication\n\t 4. Divide\n\t 5. Exit\n");
while (1){
if(ch == 1){
printf("\nEnter Two Number : ");
scanf("%d %d",&a,&b);
printf("\nAddition : %d + %d = %d\n",a,b,add(a,b));}
else if(ch == 2){
printf("\nEnter Two Number : ");
scanf("%d %d",&a,&b);
printf("\nSubtraction : %d - %d = %d\n",a,b,sub(a,b));}
else if(ch == 3){
printf("\nEnter Two Number : ");
scanf("%d %d",&a,&b);
printf("\nMulitiplication : %d x %d = %d\n",a,b,mult(a,b));}
else if(ch == 4){
printf("\nEnter Two Number : ");
scanf("%d %d",&a,&b);
printf("\nDivide : %d / %d = %d\n",a,b,div(a,b));}
else if(ch == 5){
printf("\n\tEXIT\n");
break;}
else
printf("\nInvalid Input\n");
}
}
Output :
Aim: Write a program in c to allies grades to a student according to
their percentage.
Program :
#include<stdio.h>
int main(){
int marks;
if(marks<0 || marks>100){
printf("\n Wrong Entry \n");
}
else if(marks<30){
printf("\n Grade F \n");
}
else if(marks<50){
printf("\n Grade E \n");
}
else if(marks>=50 && marks<60){
printf("\n Grade D \n");
}
else if(marks>=60 && marks<70){
printf("\n Grade C \n");
}
else if(marks>=70 && marks<80){
printf("\n Grade B \n");
}
else if(marks>=80 && marks<90){
printf("\n Grade A \n");
}
else{
printf("\n Grade A+ \n");
}
}
Output :