c program notes
what is an assignment operator?
ans. An assignment operator is an operator used to assign a new value to a variable, property, event, or indexer element in the C# programming language. = is assignment operator
when we use == means we are comparing both the values and it is equal to operator
we should use "abs" before the result of any subtraction or multiplication or addition so that it would be only positive
c program to find the grades of students using if statement?
#include <stdio.h>
int main()
{
int marks;
printf("Enter your marks:");
scanf("%d",& marks);
if(100>marks&&marks>=90)
{
printf("your grade is A");
}
if(90>marks&&marks>=80)
{
printf("your grade is B");
}
if(80>marks&&marks>=70)
{
printf("your grade is C");
}
if(70>marks&&marks>=60)
{
printf("your grade is D");
}
if(60>marks)
{
printf("your grade is E");
}
return 0;
}
- any operator is used on three operands or variables is known as Ternary Operator. Ternary operator is a?b:c it say that the condition a is true b will be executed else c will be executed.
code to find weather the student is pass or fail with overall 40% of marks in three subjects?
Ans.
#include <stdio.h>
int main()
{
int englishmarks;
int telugumarks;
int hindimarks;
int sum;
printf("Enter you're marks in english:\n");
scanf("%d",&englishmarks);
printf("Enter you're marks in telugu:\n");
scanf("%d",&telugumarks);
printf("Enter you're marks in hindi:\n");
scanf("%d",&hindimarks);
sum=englishmarks+telugumarks+hindimarks;
sum>120?printf("youre pass"):printf("youre fail");
return 0;
}
C program to find weather student is pass or fail he should have overall 40 percent marks and individual 33 percent marks in each subject assume only 3 subjects?
ans.
#include <stdio.h>
int main()
{
int englishmarks;
int telugumarks;
int hindimarks;
int sum;
printf("Enter you're marks in english:\n");
scanf("%d",&englishmarks);
printf("Enter you're marks in telugu:\n");
scanf("%d",&telugumarks);
printf("Enter you're marks in hindi:\n");
scanf("%d",&hindimarks);
sum=englishmarks+telugumarks+hindimarks;
if((sum<40)||(englishmarks>33)||(telugumarks>33)||(hindimarks>33)){
printf("you are fail");
}
else{
printf("you are pass");
}
return 0;
}
C program to find the income tax of a person depending on his income?
ans.
#include <stdio.h>
int main()
{
int income;
float tax;
printf("Enter your annual income");
scanf("%d",&income);
if(income<250000){
printf("no need to pay tax");
}
if((income>250000)&&(income<500000)){
tax=0.05*(income);
printf("you are required to pay %f",tax);
}
if((income>500000)&&(income<1000000)){
tax=0.20*(income);
printf("you are required to pay %f",tax);
}
if(income>1000000){
tax=0.30*(income);
printf("you are required to pay %f",tax);
}
return 0;
}
c program to fihe weather a letter entered by user is upper case or lower case?
ans.
#include <stdio.h>
int main()
{
char ch;
printf("enter the caharacter:\n");
scanf("%c", & ch);
if(ch>='a'&& ch<='z'){
printf("it is lowercase");
}
else if(ch>='A'&& ch<='Z'){
printf("it is uppercase");
}
else{
printf("it is not alphabet");
}
return 0;
}
Here's a table containing commonly used types in C programming for quick access.
Type Size (bytes) Format Specifier int
at least 2, usually 4 %d
,%i
char
1 %c
float
4 %f
double
8 - %lf
C program to find the largest number of four numbers given by user?
ans.
#include <stdio.h>
int main()
{
int a,b,c,d;
printf("Enter the first numbers:");
scanf("%d",&a);
printf("Enter the second numbers:");
scanf("%d",&b);
printf("Enter the third numbers:");
scanf("%d",&c);
printf("Enter the fourth numbers:");
scanf("%d",&d);
if(a>=b&&a>=c&&a>=d){
printf("%d is greater than all the numbers",a);
}
else if(b>=a&&b>=c&&b>=d){
printf("%d is greater than all the numbers",b);
}
else if (c>=a&&c>=b&&c>=d){
printf("%d is greater than all the numbers",c);
}
else if(d>=a&&d>=b&&d>=c){
printf("%d is greater than all the numbers",d);
}
return 0;
}
c program to print 10 to 20 integers?
ans
#include <stdio.h>
int main()
{
int i=0;
while(i<=20){
if(i>=10){
printf("%d\n",i);
}
i++;
}
return 0;
}
c program to print n natural numbers using do while loop?
ans.
#include <stdio.h>
int main()
{
int i=0;
int a;
printf("enter a number");
scanf("%d",& a);
do{
printf("The natural numbers are %d \n",i);
++i;
}while(a>=i);
return 0;
}
c program to print n natural using for loop?
and.
#include <stdio.h>
int main()
{
int i=0;
int a;
printf("enter a number");
scanf("%d",& a);
for(i=0;i<=a;++i){
printf("the values are %d\n",i);
}
return 0;
}
c program to print numbers in reverse order?
ans.
#include <stdio.h>
int main()
{
int i;
int a;
printf("enter a number");
scanf("%d",& a);
for(i=a;i;i--){
printf("the values are %d\n",i);
}
return 0;
}
c program to find the multiplication table of a given number?
ans.
#include <stdio.h>
int main()
{
int table;
int i=0;
int step;
printf("which multiplication table do you want:\n");
scanf("%d",& table);
while(i<=10){
printf("%d*%d=%d \n",table,i,table*i);
i++;
}
eturn 0;
}
c program to find the multiplacation table of a given number in reverse order?
ans.
#include <stdio.h>
int main()
{
int table;
int i=10;
int step;
printf("which multiplication table do you want:\n");
scanf("%d",& table);
while(i>=1){
printf("%d*%d=%d \n",table,i,table*i);
}
return 0;
}
- += Add AND assignment operator. It adds the right operand to the left operand and assigns the result to the left operand. C += A is equivalent to C = C +
ans.
#include <stdio.h>
int main()
{
int i=0;
int n=10;
int sum;
while(i<=10){
sum+=i;
i++;
}
printf(" the sum of ten natural numbers is %d",sum);
return 0;
}
The sum of ten natural numbers with a do-while loop?
ans.
#include <stdio.h>
int main()
{
int i=0;
int sum;
do{
sum+=i;
i++;
}while(i<=10);
printf("teh sum is %d",sum);
return 0;
}
program to calculate the sum of numbers occurring in multiplication table
ans.
#include <stdio.h>
int main()
{
int no;
int i=0;
int sum;
printf("enter the number of table which you need:");
scanf("%d",&no);
while(i<=10){
printf("%d*%d=%d\n",no,i,no*i);
sum+=no*i;
i++;
}
printf(" the occuring from the multiplacation of table is %d",sum);
}
c program to find the factorial of a number?
ans.
#include <stdio.h>
int main()
{
int no;
int i;
int factorial=1;
printf("enter the number for which you need factorial:");
scanf("%d",&no);
for(i=1;i<=no;i++){
factorial=factorial*i;
}
printf("%d",factorial);
}
c program to find the factorial of a number using while loop?
ans.
#include <stdio.h>
int main()
{
int no;
int i=1;
int factorial=1;
printf("enter the number for which you need factorial:");
scanf("%d",&no);
while(i<=no){
factorial=factorial*i;
i++;
}
printf("%d",factorial);
}
.c program to find the average of a numbers using functions?
ams.
#include <stdio.h>
float average(int a, int b, int c);
int main(){
int a,b,c;
printf("enter the value of A:");
scanf("%d",&a);
printf("enter the value of B:");
scanf("%d",&b);
printf("enter the value of C:");
scanf("%d",&c);
printf("the average is %f",average(a,b,c));
}
float average(int a,int b,int c){
float result;
result=(a+b+c)/3;
return result;
}
c program to convert celsius to Fahrenheit using functions?
ans.
#include <stdio.h>
float temperature(float celsius);
int main(){
float celsius;
printf("enter the value of celsius:");
scanf("%f",&celsius);
printf("the value in fahrenheit %f:",temperature(celsius));
}
float temperature(float celsius){
float fahrenheit;
fahrenheit = (celsius * 9 / 5) + 32;
return fahrenheit ;
}
- The digits after the decimal point specify the precision - the minimum number of digits which will be written. .1 and . 01 both say to put at least 1 digit, and to pad the result with zeros if there is fewer than 1 digit. Plain %f is equivalent to %.
(doubt)
(doubt)
- In Call by value, a copy of the variable is passed whereas in Call by reference, a variable itself is passed. In Call by value, actual and formal arguments will be created in different memory locations whereas in Call by reference, actual and formal arguments will be created in the same memory location.
Comments
Post a Comment