Subscribe Us

C Programming

Problem 1 swapping two number without function

#include<stdio.h>

int main()

{

int x,y,z;

scanf("%d%d",&x,&y);//x=2,y=5

x=x+y;//7

y=x-y;//7-5=2

x=x-y;//7-2=5

printf("%d %d",x,y);

return 0;

}

Problem 2 : Average of three number without function

#include<stdio.h>

int main()

{

int a,b,c;

float d;

scanf("%d%d%d",&a,&b,&c);

printf("%d %d %d ", a,b,c);

d=(a+b+c)/3.00;// explicit type casting

printf("%.2f", d);

return 0;

}

 Problem 3 : Armstrong number 
//1^3+5^3+3^3=153
#include<stdio.h>
#include<math.h>
int main()
{
int n, rem, sum=0, b;
scanf("%d",&n);
b=n;
while(n>0)
{
rem=n%10;
n=n/10;
sum=sum+pow(rem,3);
}
if(sum==b)
{
printf("Armstrong number");
}
else
{
printf("Not Armstrong Number");
}
return 0;
}

Problem 4 : Basic four mathematical operation with the help of switch case

#include<stdio.h>
int main()
{
float a,b,c;
char ch;
printf("enter the 1st no :");
scanf("%f", &a);
fflush(stdin);//clear the input buffer
printf("enter user device to perform the operation: ");
scanf("%c",&ch);
printf("enter the 2nd no :");
scanf("%f",&b);
switch(ch)
{
case'+': c=a+b;
printf("output=%f",c);
break;
case '-':c=a-b;
printf("output=%f",c);
break;
case '*':c=a*b;
printf("output=%f",c);
break;
case '/':c=a/b;
printf("output=%f",c);
break;
}
return 0;
}

Problem 5 : Check a number is prime number or not 

#include<stdio.h>
void prime(int);
int main()
{
int x;
scanf("%d",&x);
prime(x);
return 0;
}
void prime(int a)
{
int i, c=0;
for(i=1;i<=a/2;i++)
{
if(a%i==0)
{
c++;
}
}
if(c==1)
   printf("Prime");
else
printf("Not prime");
}

Problem 6 : Find Factorial of a number 

#include<stdio.h>
void fact(int);
int main()
{
int x;
scanf("%d",&x);
if(x>0)
{
fact(x);
}
else
{
printf("Enter postive number");
}
return 0;
}

void fact (int a)
{
int f=1, i;
for(i=1;i<=a;i++)
{
f=f*i;
}
printf("The factorial of %d is %d ", a,f);
}

0 Comments:

Post a Comment

If you have any doubts . Please let me know.

Powered by Blogger.

Ad Code

Responsive Advertisement

Ad Code

Responsive Advertisement

Featured post

Search This Blog

Recently added book names

THE HTML AND CSS WORKSHOP   | MICROSOFT POWER BI COOKBOOK   | MongoDB in Action, 2nd Edition  | ADVANCED DEEP LEARNING WITH PYTHON   | Cracking Codes with Python An Introduction to Building and Breaking  | Moris Mano Degital Design 3rd Edition  | Beginning App Development with Flutter by Rap Payne  |react hooks in Action - John Larsen   | Artificial Intelligence A Modern Approach Third Edition Stuart Russel  | Data Structures and Algorithms - Narasimha Karumanchi   | Thomas S.M. - PostgreSQL High Availability Cookbook - 2017  | Gunnard Engebreth PHP 8 Revealed Use Attributes the JIT Compiler   | ICSE Class X Computer Application Notes   | INTERNET OF THINGS PROJECTS WITH ESP32   | 100 aptitude trick(102pgs)s   | OBJECT_ORIENTED_PROGRAMMING Question & Answer   | C questions and answer   | Full_Book_Python_Data_Structures_And_Algorithm   | Jira 8 Administration Cookbook Third Edition  | KALI LINUX WIRELESS PENETRATION TESTING BEGINNERS GUIDE THIRD EDITION - Cameron Buchanan, Vivek Ramachandran  HTML5 & javascript By :- Jeanine Meyer   | Python For Beginners Ride The Wave Of Artificial Intelligence   | HackingTheXbox   | Introduction to Algorithms 3rd.Edition - (CLRS)   | The C++ Programming Language - Bjarne Stroustrup   | Modern C++ Programming Cookbook - Marius Bancila   | Java The Complete Reference Eleventh Edition   Data_Communications and Networking 4th Ed Behrouz A Forouzan   | DevOps with Kubernetes - Hideto Saito   | The-Linux-Command-Line-A-Complete-Introduction   | Assembly Language for X86 Processors KIP R. Irvine   | Effective_Modern_C++ - Scott Meyer

Contact Form

Name

Email *

Message *

Followers

Mobile Logo Settings

Mobile Logo Settings
image

Computer Training School Regd. under Govt. of West Bengal Society Act 1961

Header Ads Widget

Responsive Advertisement

Hot Widget

random/hot-posts

Recent in Sports

Popular Posts

Labels

Blogger templates