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 OperatorTernary 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.

    TypeSize (bytes)Format Specifier
    intat least 2, usually 4%d, %i
    char1%c
    float4%f
    double8
    • %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 +     
c program to find the sum of ten natural numbers?

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 %.

c program to find the force of the given body with functions?
ans.

#include <stdio.h>
float force(float mass);
int main(){
    int m;
    printf ("enter the value of mass:");
    scanf("%d",& m);
    printf("the force of the body is%.2f",force(m));
}
float force(float mass){
    float result=mass*9.8;
    return result;
}
c program to find the Fibonacci number?

(doubt)


ans.
#include <stdio.h>
int fib(int n);
int main(){
    int number;
    printf("enter the number which you need in fibonacci sequence:");
    scanf("%d",&number);
    printf("the fibonacci numberis %d",fib(number));
}
int fib(int n){
    int result=fib(n-1)+fib(n-2);
    
    return result;
}
c program to print the star pattern?

(doubt)

ans.
#include <stdio.h>
void printpattern(int n);
int main()
{
    int number;
    printf("enter how many rows do you need:");
    scanf("%d",&number);
    printpattern(number);
    return 0;
}
void printpattern(int n)
{
    
    
    for(int i=0;i<(2*n-1);i++){
     printf("*");
        
    }
   printf("\n");
    
   }

  •  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.
c program to print the address of the variable and use the address to get the value of the variable?
ans.
#include <stdio.h>

int main()
{
    int a=2;
    int *ptr;
    ptr=&a;
    
    printf("the value of a is :%d\n", a);
    printf("the value of a is %d\n", *ptr);
    printf("the address of a is %u:\n ",&a);
    printf("the address of a is %u:\n ",ptr);
     

    return 0;
}
c program to increase the value of the variable by 10 and pass it through function by call by reference?
ans.
#include <stdio.h>
int inc(int *a);

int main()
{
    int a=5;
    inc(&a);
    printf(" the value is increased by 10 times %d\n",a);

    return 0;
}
int inc(int *a){
   *a=*a*10;
   
    
}
c program to find sum and average by call by reference?
ans.
#include <stdio.h>
void sumandaverage(int a,int b,int *sum,float *average);
int main(){
    int a=4;
    int b=5;
    int sum;
    float average;
    sumandaverage(a,b,&sum,&average);
    printf("%d\n",sum);
    printf("%f\n",average);
    
}
void sumandaverage(int a,int b,int *sum,float *average){
   *sum=a+b;
   *average=(*sum)/2;
}


#include <stdio.h>
void sumandaverage(int a,int b,int *sum,float *average);
int main(){
    int a=4;
   int *ptr;
   int **ptr_ptr;
   ptr=&a;
   ptr_ptr=&ptr;
    printf("%d\n",*ptr);
    printf("%d\n",**ptr_ptr);
    
}

c program to store marks of the students using arrays?
ans.

#include <stdio.h>

int main()
{
    int marks[5];
    int i;
    for(i=0;i<5;i++){
    printf("enter the marks of student %d:\n ",i+1);
    scanf("%d",&marks[i]);
    }
     
    printf(" the marks of student is %d %d %d %d %d:\n ",marks[0],marks[1],marks[2],marks[3],marks[4]);
     

    return 0;
}

c program to print 5 multiplication table using arrays?
ans
#include <stdio.h>

int main()
{
    int mul[10];
    
    for(int i=0; i<10; i++){
        mul[i]=5*(i+1);
        
    }
     for(int i=0; i<10; i++){
        printf("5X%d=%d\n",(i+1),mul[i]);
        
    }

    return 0;
}


c program to reverse the function?
ans.
#include <stdio.h>

void reversearr( int *arr,int n){
    for(int i=0; i<(n/2); i++ )
    {
        int temp;
        temp = arr[i];
        arr[i]=arr[n-i-1];
        arr[n-i-1]=temp;
    }
    
}
int main(){
int arr[]={1,2,3,4,5,6,7};
reversearr(arr,7);
 for(int i=0;i<7;i++){
printf("the value of %d is %d\n",i,arr[i]);

     
 }

}

c program to store the marks of the students using arrays?
ans.
#include <stdio.h>
int main(){
    int marks[5];
    int i=0;
    for(i=0;i<5;i++){
        printf("enter the marks of the student[%d]:",i+1);
        scanf("%d",&marks[i]);
        
    }
 
}
c program to create a array using pointer arithmetic where pointer is pointing towards the first element?
ans.
#include <stdio.h>
int main(){
    int arr[10];
    int *ptr=arr;
    ptr=ptr+2;
    if(ptr==&arr[2]){
        printf("it points same location in the memory");
    }
    else{
        printf("it does not point");
    }
}

printing 5 tables using an array?

ans.
#include <stdio.h>

int main()
{
    int mul[10];
    for(int i=0;i<10;i++){
        mul[i]=5*(i+1);
        printf("5 X %d= %d\n",i+1,mul[i]);
    }
}
c program to reverse the elements in the array?
ans.
#include <stdio.h>
void reverse(int*arr,int n){
    int temp;
    for(int i=0;i<n/2;i++){
        temp=arr[i];
    arr[i]=arr[n-i-1];
    arr[n-i-1]=temp; 
    }
   
    
}
int main(){
    int arr[]={1,2,3,4,5,6,7};
    reverse(arr,7);
    for(int i=0;i<=7;i++){
        printf("the reverse order of %d is %d\n",i,arr[i]);
    }

CProgrammingServer Side Programming. The function fflush(stdin) is used to flush the output buffer of the stream. It returns zero, if successful otherwise, returns EOF and feof error indicator is set
 
c program to create a function like strlen?
ans
#include <stdio.h>
int strln(char *st){
char *ptr=st;
int len=0;
 while(*ptr!='\0'){
    len++;
    ptr++;
    
}

    return len;
}

int main()
{
    char st[]="junaid";
    int l=strln(st);
    printf("the length of the string is:%d",l);
    

    return 0;
}

c program to slice a string and print the string?
and:

#include <stdio.h>
void slice(char *st, int m, int n){
    int i=0;
    while((m+i)<n){
        st[i]=st[i+m];
        i++;
    }
    st[i]='\0';
    
}

int main()
{
    char st[]="junaid";
    slice(st,1,6);
    printf("The sliced string is:%s",st);

    return 0;
}

c program to create a function like strcpy?
ans:

(doubt)

#include <stdio.h>

char strcp(char *tar, char *st){
    int i=0;
    char *start = tar;
    while(st!='\0'){
        tar[i]=st[i];
        i++;
        
    }
    tar='\0';
    return start;
    
}

int main()
{
    char st[]="junaid";
    char tar[]="ubaid";
    strcp(tar,st);
    printf("The copied string is:%s");

    return 0;
}

c program to encrypt the given string?
ans.
#include <stdio.h>
void encrypt(char *c){
    char *ptr=c;
    while(*ptr!='\0'){
        *ptr=*ptr+1;
        ptr++;
        
    }
    }

int main()
{
    char str[]="junaid";
    encrypt(str);
    printf("The encrypted string is:%s",str);
    
   }
c program to decrypt the given string ?
ans.

#include <stdio.h>
void decrypt(char *c){
    char *ptr=c;
    while(*ptr!='\0'){
        *ptr=*ptr-1;
        ptr++;
        
    }
    }

int main()
{
    char str[]="kvobje";
    decrypt(str);
    printf("The decrypted string is:%s",str);
    
   }
c program to find the occurrence of the character in given string?
ans.
#include <stdio.h>
int occurance(char st[],char c){
    int count;
    char *ptr=st;
    while(*ptr!='\0'){
        if(*ptr==c){
            count++;
            
        }
       
        ptr++;
        
    }
    return count;
    }

int main()
{
    char str[]="junaidjjjjjjj";
   int count=occurance(str,'j');
    printf("occurance is:%d",count);
    
   }
c program to find the prence of the given character in the string?
ans.

(doubt)

#include <stdio.h>
int check(char st[],char c){
    
    char *ptr=st;
    int count;
    while(*ptr!='\0'){
        if(*ptr==c){
            count=1;
            }
        else{
            count=0;
            
        }
        ptr++;
    return count;
     }

int main()
{
    char str[]="junaid";
  int count= check(str,'j');
  if(count==1){
      printf("it is there");
  }
   else{
      printf("it is not there");
  }
 }

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main()
{
    int a=10,b=4;
    float c=4.0,d=2.0;
    int sum,substraction;
    float add,sub;
    printf("ENTER THE FIRST INT NUMBER:");
    scanf("%d",&a);
     printf("ENTER THE SECONDINT NUMBER:");
    scanf("%d",&b);
  printf("ENTER THE FIRST FLOAT NUMBER:");
    scanf("%d",&c);
  printf("ENTER THE SECOND FLOAT NUMBER:");
    scanf("%d",&d);
    sum=a+b;
    substraction=a-b;
    printf("the sum of the numbers is %d and substraction of numbers is %d",sum,substraction);
    
     printf("the sum of the numbers is %f and substraction of numbers is %f",add,sub);
    
    return 0;
}










Comments

Popular posts from this blog

PYTHON NOTES