Python Tutorial - Python Full Course for Beginners
Programming with Mosh
Introduction to Python Programming
If you're looking to get started with programming, Python is a great language to learn. It's one of the most popular programming languages out there, with a strong community of users and d...
,2. Arithmetic Operator in C programming
ARITHMETIC
OPERATION EXAMPLE
OPERATORS
+ Addition 10 + 2 = 12
– Subtraction 10 – 2 = 8
* Multiplication 10 * 2 = 20
/ Division = 5
Modulus – It returns the remainder 10 % 2 = 0 (Here remainder is zero). If it is 10
%
after the division % 3 then it will be 1.
Question-1 :The distance between two cities (in km.) is input through the keyboard. Write a program to convert
and print this distance in meters, feet, inches and centimeters.
#include<stdio.h>
int main()
{
float km,m,cm,ft,i;
printf("Enter The Kilometer : ");
scanf("%f",&km);
m=km*1000;
cm=m*100;
i=cm/2.54;
ft=i/12;
printf("\n KM : %0.2f",km);
printf("\n M : %0.2f",m);
printf("\n CM : %0.2f",cm);
printf("\n IN : %0.2f",i);
2
, printf("\n FT : %0.2f",ft);
return 0;
}
Output
Enter The Kilometer : 30
KM : 30.00
M : 30000.00
CM : 3000000.00
IN : 1181102.38
FT : 98425.20
2.Calculate the sum of digits
#include<stdio.h>
int main()
{
int n,sum=0,m;
printf("Enter a number:");
scanf("%d",&n);
while(n>0)
{
m=n%10;
sum=sum+m;
n=n/10;
}
printf("Sum is=%d",sum);
return 0;
}
Enter a number:654
Sum is=15
Logical Operators in C
Operator Example Meaning
&& (Logical AND) expression1 && expression2 true only if both expression1 and expression2 are true
|| (Logical OR) expression1 || expression2 true if either expression1 or expression2 is true
! (Logical NOT) !expression true if expression is false and vice versa
#include<stdio.h>
int main()
{
int a=32; //>=35 and(&&) <=100
printf("\nLogical And : %d",(a>=35 && a<=100));
printf("\nLogical Or : %d",(a>=35 || a<=100));
printf("\nLogical Not : %d",!(a>=35));
return 0;
}
3
, Output
Logical And : 0
Logical Or : 1
Logical Not : 1
2. Program to validate the username and password entered by the user is correct or not using the predefined
username and password.
#include <stdio.h>
#include <string.h>
// use #define macro to define the values for UserName and Password
#define UserName "system"
#define Password "admin@123"
int main ()
{
// declare character type array
char un[50], pass[50];
// take UserName and Password from user
printf ( " Enter the username: " );
scanf (" %s", un);
printf ( " Enter the password: " );
scanf (" %s", pass);
// use if statement and Logical AND operator to validate the condition
if (strcmp (UserName, un) == 0 && strcmp (Password, pass) == 0)
{
printf (" \n The user's credentials are correct. ");
}
else
{
printf ( " \n The user's credentials are incorrect. ");
}
return 0;
}
Output
Enter the username: system
Enter the password: admin@123
The user's credentials are correct.
Relational operators
#include< stdio.h>
int main()
{
int p, q, r;
p = 9;
q = 10;
r = p == q;
printf("%d", r);
4
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller avgaming. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $7.99. You're not tied to anything after your purchase.