#include<stdio.h>
#include<conio.h>
int main()
{
int i,num,sum=0,hmarks;
int arr[20];
float avg;
printf("\nenter the number of students :");
scanf("%d",&num);
printf("\nenter the marks of the students\n");
for(i=0;i<num;i++)
{
scanf("\n%d",&arr[i]);
sum=sum+arr[i];
}
printf("\ntotal marks of students :%d",sum);
avg=sum/num;
printf("\naverage marks of the students :%f",avg);
for(i=0;i<num;i++)
{
}
return 0;
}
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
printf("\nenter the value of a = ");
scanf("%d",&a);
printf("\nenter the value of b = ");
scanf("%d",&b);
a=a+b;
b=a-b;
a=a-b;
printf("\nafter swaping the values");
printf("\nvalue of a = %d",a);
printf("\nvlaue of b = %d",b);
return 0;
}
#include<stdio.h>
#include<conio.h>
int main()
{
int i;
//print 1 to 100 using while loop
while(i<=100)
{
printf("%d",i);
i++;
}
//print 1 to 100 using do while
do
{
printf("%d",i);
i++;
}
while(i<=100);
//print 1 to 100 using for loop
for(i=1;i<100;i++)
{
printf("%d\n",i);
}
return 0;
}
How to make an easy calculator of four operations ( + , – , * , / ) by using switch case in c programming.
Codes are here….
Let see the codes
#include<stdio.h> int main() { int a,b,c,result; char operator;
printf("enter your choice\n1=+\n2=-\n3=*\n4=/\n"); scanf("%c",&operator);
printf("enter two numbers\n"); scanf("%d%d",&a,&b);
switch(operator) Â Â Â { Â Â Â case'1': Â Â Â Â Â Â Â result=a+b; Â Â Â Â Â Â Â break; Â Â Â case'2': Â Â Â Â Â Â Â result=a-b; Â Â Â Â Â Â Â break; Â Â Â case'3': Â Â Â Â Â Â Â result=a*b; Â Â Â Â Â Â Â break; Â Â Â case'4': Â Â Â Â Â Â Â result=a/b; Â Â Â Â Â Â Â break; Â Â Â default: Â Â Â Â Â Â Â printf("\nyou have entered blank option"); Â Â Â }
printf("\nresult is =%d",result);Â Â Â getchar(); }
Output:
enter your choice 1=+ 2=- 3=* 4=/ 1 enter two numbers 10 20 result is =30 [Process completed - press Enter]