Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 0 additions & 140 deletions Merge Sort in C.

This file was deleted.

68 changes: 36 additions & 32 deletions calculator.c
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
//C program to display simple calculator.

#include<stdio.h>
#include<math.h>
int main()
{
float n1,n2; //Declaring two float varibles, which we will later use as two operands.
char operator; //The operator is a char varible which will store our choice of operator. ex. +, -, *, /
printf("Enter an operator(+,-,/,*,^):");
scanf("%c",&operator); //Taking input from user as what operation they want to perform.

printf("Enter two numbers:");
scanf("%f%f",&n1,&n2); //Taking float inputs as operands and storing then in n1 and n2 respectively

switch(operator) //Here depending upon the operator input switch statement will decide which case to execute
{
//The %.3f will allow only three values after the dot(.) to print in the float
case'+' : printf("%.3f + %.3f = %.3f",n1,n2,(n1+n2));
break;
case'-' : printf("%.3f - %.3f = %.3f",n1,n2,(n1-n2));
break;
case'/' : printf("%.3f / %.3f = %.3f",n1,n2,(n1/n2));
break;
case'*' : printf("%.3f * %.3f = %.3f",n1,n2,(n1*n2));
break;
case'^' : printf("%.3f ^ %.3f = %.3f",n1,n2,pow(n1, n2));
break;
default: printf("Error! operator is wrong");

}
return 0;
}
#include<stdio.h>
int main()
{
int a, b;
char op;
int result;
printf("Enter First Number:");
scanf("%d", &a);
printf("Enter Second Number:");
scanf("%d", &b);
printf("Enter Operator of the Operation you want to perform :");
scanf(" %c", &op);
switch (op)
{
case '+':
result=a+b;
printf("The Sum Is %d", result);
break;
case '-':
result=a-b;
printf("The Subtract Is %d", result);
break;
case '*':
result=a*b;
printf("The Multiply Is %d", result);
break;
case '/':
result=a/b;
printf("The Division Is %d", result);
break;
default:
printf("Please Enter a valid Operator");
break;
}
return 0;
}
21 changes: 11 additions & 10 deletions primeinrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
#include<stdio.h>
void main()
{
int num,i,count;
printf("Prime numbers b/w 1 to 100:");
int num,i,count; //initialization of variables
printf("Prime numbers b/w 1 to 100:\n");

for(num=1;num<=100;num++)
for(num=1;num<=100;num++) //loop to iterate number from 1 to 100
{
count=0;
for(i=2;i=(num/2);i++)
count=0;
for(i=2;i<=(num/2);i++)
{
if(num%i==0)
if(num%i==0) // if number is divisible by i then it is not a prime number
{
count++;
break;
count++; // so increment the count
break; // breaking the loop
}
}
if(count==0&&num!=1)
if(count==0&&num!=1) //checking whether it is a prime number or not if it is a prime number
{
printf("%d",num);
printf("%d ",num); //print the number

}
}
}