C Program Output
C Program Output
#include<stdio.h>
int main()
{
int ivar; floatfvar;
char svar[100];
printf("\nEnter the integer value: ");
scanf("%d",&ivar);
printf("\nEnter the float value : ");
scanf("%f",&fvar);
printf(“\nEnter the string value: ");
scanf("%s",&svar);
printf("\n");
printf("\nInteger value is : %d",ivar);
printf("\nFloat value is : %f",fvar);
printf("\nEntered string is : %s",svar);
return0;
}
Program:
/*To evaluate area of triangle (sqrt(s(s-a)(s-b)(s-c)*/
#include<stdio.h>
#include<math.h>
voidmain()
{
int a,b,c;
floats,area;
printf("enter the values of a,b,c");
scanf("%d%d%d",&a,&b,&c);
s=(a+b+c)/2.0;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("The area of a trangle is =%f",area); getch();
}
Program:
#include <stdio.h>
int main()
{
intnum;
/* Input number from user */
printf("Enter any number: ");
scanf("%d", &num);
if(num > 0)
{
printf("Number is POSITIVE");}
if(num < 0)
{
printf("Number is NEGATIVE");
}
if(num == 0)
{
printf("Number is ZERO");
}
return 0;
}
Program:
#include <stdio.h>
void main( )
{
int x, y;
printf("Enter the value of x:\n");
scanf("%d",&x);
printf("Enter the value of y:\n");
scanf("%d",&y);
if (x >y )
{
printf("x is Greater");
}
else
{
printf("y is Greater");
}
}
Program:
#include <stdio.h>
void main( )
{
int a, b, c;
printf("Enter 3 numbers..."); scanf("%d%d%d",&a, &b, &c);
if(a > b)
{
if(a > c)
{
printf("a is the greatest");
}
else
{
printf("c is the greatest");
}
}
else
{
if(b > c)
{
printf("b is the greatest");
}
else
{
printf("c is the greatest");
}
}
}
Program:
#include <stdio.h>
void main( )
{
int a;
printf("Enter a number...");
scanf("%d", &a);
if(a%5 == 0 && a%8 == 0)
{
case '*':
result = num1 * num2;
break;
case '/':
result = num1 / num2;
break;
default:
printf("Invalid operator");
}
/*Prints the result*/
printf("%.2f %c %.2f = %.2f", num1, op, num2, result);
getch();
}
Program:
#include <stdio.h>
int main() {
int num, originalNum, remainder, result = 0;
printf("Enter a three-digit integer: ");
scanf("%d",&num);
originalNum =num;
while (originalNum!= 0)
{
// remainder contains the last digit
remainder = originalNum % 10;
result += remainder * remainder * remainder;
//result += pow(remainder, n);
// removing last digit from the orignal number
originalNum /= 10;
}
if (result == num)
printf("%d is an Armstrong number.", num);
else
printf("%d is not an Armstrong number.", num);
return0;
}
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int num;
clrscr();
printf(“\nOdd or Even Number\n”);
printf(“\n\nEnter an integer you want to check:”);
scanf(“%d”,&num);
if((num%2)==0)
{
printf(“%d is an Even number”,num);
}
else
{
printf(“%d is an Odd number”,num);
}
getch();
}
Program:
#include<stdio.h>
#include<conio.h>
voidmain()
{
int i,num;
longint fact=1;
printf(“ENTER A NUMBER: “);
scanf(“%d”,&num);
for(i=1;i<=num;i++)
{
fact*=i;
}
printf(“THE FACTORIAL OF %d IS %ld”,num,fact);
getch();
}
Program:
#include<stdio.h>
Intmain()
{
int avg = 0,sum =0,x=0,num[4];
for (x=0; x<4;x++)
{
printf("Enter number %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<4;x++)
{
sum = sum + num[x];
}
avg = sum/4;
printf("Average of entered number is: %d\n", avg);
return 0;
}
Program:
#include<stdio.h>
int main()
{
int disp[2][3]; int i,j;
for(i=0; i<2; i++)
{
for(j=0;j<3;j++)
{
printf("Enter value for disp[%d][%d]:",i,j);
scanf("%d",&disp[i][j]);
}
}
printf("Two Dimensional array elements:\n");
for( i=0;i<2;i++){ for(j=0;j<3;j++){
printf("%d",disp[i][j]); if(j==2){
printf("\n");
}
}
}
return 0;
}
Program:
#include<stdio.h>
#include<conio.h>
void swap(int*,int *);
void main()
{
int a,b;
printf(“Enter any two number:\n);
scanf(“%d\n%d”,&a,&b);
printf(“\n Before the swapping:a=%d,b=%d”,a,b);
swap(&a,&b);
printf(“\n After the swapping:a=%d,b=%d”,a,b);
getch();
}
void swap(int *p,int *q)
{
int tmp;
tmp=*p;
*p=*q;
*q=tmp;
}
Program:
#include<stdio.h>
#include<conio.h>
int checkPrimeNumber(int n);
int main()
{
int n1,n2,i,flag;
clrscr();
printf(“Enter two positive integers :\n”);
scanf(“%d\n%d”,&n1,&n2);
printf(“Prime numbers between %d and %d are :\n”,n1,n2);
for(i=n1+1;i<n2;++i)
{
//flag will be equal to 1 if i is prime
flag=checkPrimeNumber(i);
if(flag==1)
printf(“%d\n”,i);
}
return 0;
}
//user-defined function to check prime number
int checkPrimeNumber(int n) {
int j,flag=1;
for(j=2;j<n/2;++j)
{
if(n%j==0)
{
flag=0;
break;
}
}
return flag;
}
Program:
#include <stdio.h>
void reverseSentence();
int main()
{
printf("Enter a sentence: ");
reverseSentence();
return 0;
}
void reverseSentence()
{
char c;
scanf("%c", &c);
if (c != '\n')
{
reverseSentence();
printf("%c", c);
}
}
Program:
#include<stdio.h>
#define MAX 100
int findMaxElem(int []);
int n;
int main()
{
int arr1[MAX],mxelem,i;
printf("\n\n Function : get largest element of an array :\n");
printf(" \n");
printf(" Input the number of elements to be stored in the array :");
scanf("%d",&n);
printf(" Input %d elements in the array :\n",n);
for(i=0;i<n;i++)
{
printf(" element - %d : ",i);
scanf("%d",&arr1[i]);
}
mxelem=findMaxElem(arr1);
printf(" The largest element in the array is : %d\n\n",mxelem);
return 0;
}
break;
case '3':
fflush(stdin);
flag=0;
fp=fopen("acc.dat","r+");
printf("\nEnter the Account Number : ");
gets(ano);
for(pos1=ftell(fp);
fread(&acc,sizeof(acc),1,fp)==1;
pos1=ftell(fp))
{
if(strcmp(acc.no,ano)==0)
{
printf("\nEnter the Type 1 for deposit & 2 for withdraw : ");
scanf("%d",&type);
printf("\nYour Current Balance is : %s",acc.balance);
printf("\nEnter the Amount to transact : ");
fflush(stdin);
gets(amt);
if(type==1)
bal = atof(acc.balance) + atof(amt);
else
{
bal = atof(acc.balance) - atof(amt);
if(bal<0)
{
printf("\nRs.%s Not available in your A/c\n",amt);
flag=2;
break;
}
}
flag++; break;
}
{ }
if(flag==1)
pos2=ftell(fp);
pos = pos2-pos1;
fseek(fp,-pos,1);
sprintf(amt,"%.2f",bal);
strcpy(acc.balance,amt);
fwrite(&acc,sizeof(acc),1,fp);
}
else if(flag==0)
printf("\nA/c Number Not exits... Check it again");
fclose(fp);
break;
case '4':
fp=fopen("acc.dat","r");
flag=0;
while(fread(&acc,sizeof(acc),1,fp)==1)
{
bal = atof(acc.balance);
if(bal<MINBAL)
flag++;
}
printf("\nThe Number of Account Holder whose Balance less than the Minimum Balance
:%d",flag); fclose(fp);
break;
case '5' :
remove("acc.dat");
break;
case '6' :
fclose(fp);
exit(0);
}
printf("\nPress any keytocontinue ");
getch();
} while (choice!='6');
}