Operators :

Pos. Operator Description Method
1 :: scope Left-to-right
2 () [] . -> ++ -- dynamic_cast static_cast reinterpret_cast const_cast typeid postfix Left-to-right
3 ++ -- ~ ! sizeof() new delete unary (prefix) Right-to-left
* & indirection and reference (pointers)
+ - unary sign operator
4 (type) type casting Right-to-left
5 .* ->* pointer-to-member Left-to-right
6 * / % multiplicative Left-to-right
7 + - additive Left-to-right
8 << >> shift Left-to-right
9 < > <= >= relational Left-to-right
10 == != equality Left-to-right
11 & bitwise AND Left-to-right
12 ^ bitwise XOR Left-to-right
13 | bitwise OR Left-to-right
14 && logical AND Left-to-right
15 || logical OR Left-to-right
16 ?: conditional Right-to-left
17 = *= /= %= += -= >>= <<= &= ^= |= assignment Right-to-left
18 , comma Left-to-right

USING MACROS IN C;

QUESTION- WAP to use the #define function in a c program as an operator;

ANSWER-

#include<stdio.h>
#include<conio.h>
#define D ||
#define G &&
int main()
{
int p=10,q=20,r=30;
if((p==10) G (q<25 D r>=50))
printf(“\nCONDITION TRUE!!”);
else
printf(“\nCONDITION FALSE!!”);
printf(“\n\nPROGRAMMING AT C#ODE STUDIO”);
getch();
return 0;
}

macro

PASCAL’S TRIANGLE;

QUES- WAP  to print the pascals triangle after taking the input from user;

ANSWER-

#include<stdio.h>
#include<conio.h>
long int cal(int);
int main()
{
int i,j,r,p;
printf(“\nNo. of rows you need : “);
scanf(“%d”,&r);
for(i=0;i<r;i++)
{
for(j=0;j<=(r-i-1);j++)
printf(” “);
for(j=0;j<=i;j++)
{
p=cal(i)/(cal(j)*cal(i-j));
printf(“%ld “,p);
}
printf(“\n”);
}
printf(“\n\nPROGRAMMING AT C#ODE STUDIO”);
getch();
return 0;
}

long int cal( int num)
{
int x;
long r=1;
for(x=1; x<=num; x++)
r=r*x;
return (r);
}

pascal

PYRAMID DESIGNING;

QUESTION- WRITE A C PROGRAM TO ACCEPT NO. OF ROWS FROM USER AND DISPLAY THE NUMBER PYRAMID;

ANSWER-

#include<stdio.h>
#include<conio.h>
int main()
{
int n,r,c,q;
printf(“\nNo.of rows you want : “);
scanf(“%d”,&n);
for(r=1; r<=n; r++)
{
for(q=n-r; q>=1; q–)
printf(” “);
for(c=1; c<=r; c++)
printf(“%d”,c);
for(c=r-1; c>=1; c–)
printf(“%d”,c);
printf(“\n”);
}
for(r=1; r<=n; r++)
{
for(q=r; q>=1; q–)
printf(” “);
for(c=1; c<=(n-r); c++)
printf(“%d”,c);
for(c=n-r-1; c>=1; c–)
printf(“%d”,c);
printf(“\n”);
}
printf(“\nPROGRAMMING AT C#ODE STUDIO”);
getch();
return 0;
}

pyramid

Append Mode & Copying a file;

Question- Copy a file into new file and write more data into that file and display the records;

Answer-

#include<stdio.h>
#include<conio.h>
int main()
{
    struct student
    {
        char name[10];
        char pname[5];
        int term;
        double fee;
    }s,r,v[2];
    int i;
    FILE *f1,*f2;
    f1=fopen(“origin.txt”,”w”);
    printf(“\nNew File ORIGIN.TXT Open.”);
    printf(“\nEnter name – “);
    scanf(“%s”,&s.name);
    printf(“\nEnter Program name – “);
    scanf(“%s”,&s.pname);
    printf(“\nEnter Term id -“);
    scanf(“%d”,&s.term);
    printf(“\nEnter Fees – “);
    scanf(“%ld”,&s.fee);
    fwrite(&s,sizeof(s),1,f1);
    fclose(f1);
    printf(“\nORIGIN.TXT Opened in read mode and NEW.TXT in write mode.”);
    f1=fopen(“origin.txt”,”r”);
    f2=fopen(“new.txt”,”w”);
    fread(&r,sizeof(r),1,f1);
//reading the data from origin.txt
    fwrite(&r,sizeof(s),1,f2); //copying data to new.txt
    printf(“\nCopying completed.”);
    fclose(f1);
    fclose(f2);
    printf(“\nExsiting File NEW.TXT Open as append mode.”);
    f2=fopen(“new.txt”,”a”);
//in append mode the pointer in file is set to the last of file
    printf(“\n\nEnter name – “);
    scanf(“%s”,&s.name);
    printf(“\nEnter Program name – “);
    scanf(“%s”,&s.pname);
    printf(“\nEnter Term id -“);
    scanf(“%d”,&s.term);
    printf(“\nEnter Fees – “);
    scanf(“%ld”,&s.fee);
    fwrite(&s,sizeof(s),1,f2);
    fclose(f2);
    printf(“\nExsiting File NEW.TXT Open as read mode.”);
    f2=fopen(“new.txt”,”r”);
    for(i=0;i<2;i++)
    {
        fread(&v[i],sizeof(v[i]),1,f2);
        printf(“\n\nName= %s\nProgram name = %s\nTerm id = %d\nFees = %ld”,v[i].name,v[i].pname,v[i].term,v[i].fee);
    }
    printf(“\n\n\tPROGRAMMING @ CODE STUDIO”);
    getch();
}

 

OUTPUT-

append

CHECKING LEAP YEAR OR NOT;

QUESTION- WAP to find a year is leap year or not;

ANSWER-

#include<conio.h>
#include<stdio.h>
int main()
{
    int year,n;
    printf(“\nENTER 1 TO START:”);
    scanf(“%d”,&n);
    while(n==1)
    {
        printf(“\nENTER YEAR:”);
        scanf(“%d”,&year);
         if(((year%4==0)&&(year%100!=0))||(year%400==0))
             printf(“%d IS A LEAP YEAR”,year);
        else
             printf(“%d NOT A LEAP YEAR”,year);
          printf(“\n\nENTER 1 TO CONTINUE, 0 TO EXIT:”);
          scanf(“%d”,&n);
    }
    printf(“\n\n\tPROGRAMMING @ CODE STUDIO”);
    getch();       
}

OUTPUT–

leap

WRITE REVERSE OF A FILE IN ANOTHER;

QUESTION BY- vishwas goyal < vishwasgoyal.182@gmail.com > WAP to copy a file in reverse order..

ANSWER-

OHHHH THIS PROGRAM IS REALLY SO COMPLICATED; Smile

—————————————-

#include<stdio.h>
#include<conio.h>
int main()
{
    FILE *f1,*f2;
    f1=fopen(“input.txt”,”w”);
    char c,d[50];
    printf(“\nENTER CHARACTERS, TO QUIT PRESS q : \n”);
    c=getchar();
    while(c!=’q’)
    {
        fputc(c,f1);
        c=getchar();
    }
    fclose(f1);
    f1=fopen(“input.txt”,”r”);
    int i=0,max;
    while(!feof(f1))
    {
        c=fgetc(f1);
        d[i]=c;
        i++;
    }
    max=i;
    fclose(f1);
    f2=fopen(“output.txt”,”w”);
    for(i=max-2;i>=0;i–)
    {
        fputc(d[i],f2);
    }
    fclose(f2);
    f1=fopen(“output.txt”,”r”);
    while(!feof(f1))
    {
        c=fgetc(f1);
        printf(“%c”,c);
    }
    printf(“\n\n\tPROGRAMMING @ CODE STUDIO”);
    getch();
}

 

OUTPUT (FILES)-

file_rev1

 

OUTPUT (SCREEN)-

file_rev

BINARY TO DECIMAL;

QUESTION- WRITE A PROGRAM TO CONVERT A NO. FROM BINARY TO DECIMAL USING FN.

ANSWER;

#include<stdio.h>
#include <math.h>
#include<conio.h>
int fn1(long int);
int main()
{
    long int dec,rem,quo;
    printf(“Enter any BINARY number: “);
    scanf(“%ld”,&quo);
    fn1(quo);
    printf(“\n\n\tPROGRAMMING @CODE STUDIO”);
    getch();
}

int fn1(long int quo)
{
    long int rem,dec=0,j=1;
    while(quo!=0)
    {
        rem=fmod(quo,10);
        dec=dec+rem*j;
        j=j*2;
        quo=quo/10;
    }
    printf(“\nEQUIVALENT DECIMAL NO. IS %ld”,dec);
   
}

 

OUTPUT-

bin_dec

WORKING WITH STRINGS;

QUESTION- CONVERT STRING FROM UPPER CASE TO LOWER CASE( VICE VERSA ALSO ) AND CHECK IF 2 STRINGS ARE SAME;

ANSWER;

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
    int m;
    char a[10],b[10],c[10],d[10],e[10],f[10],*co;
    printf(“Input string a in lower case:”);
    scanf(“%s”,&a);
    strcpy(b,a);
    printf(“\nB is =”);
    printf(“%s”,b);
    strupr(b);
    printf(“\nUpper case:”);
    printf(“%s”,b);
    printf(“\n\nChecking for equal strings\nInput string d:”);
    scanf(“%s”,&d);
    printf(“\nInput string e:”);
    scanf(“%s”,&e);
    m=strcmp(d,e);
    if(m==0)
        printf(“\nString d and e are same”);
    else
        printf(“\nString d and e are not equal”);
    printf(“\n\nConvering to lower case\nInput string in f in upper case:”);
    scanf(“%s”,&f);
    strlwr(f);
    printf(“\nf in lower case :”);
    printf(“%s”,f);
    printf(“\n\n\tPROGRAMMING @ CODE STUDIO”);
    getch();

}

OUTPUTS-

STRM

Fibonacci series using fn and recursion;

#include<stdio.h>
#include<conio.h>
int f(int a); //PROTOTYPE TO SECOND FN.//
int main()
{
int a;
printf(“\nINPUT A NUMBER:”);
scanf(“%d”,&a);
printf(“\nSERIES IS :\n”);
for(int i=0;i<a;i++)
printf(“%d\t”,f(i));
printf(“\n\n\tPROGRAMMING @ CODE STUDIO”);
getch();
}

int f(int a) //fn 2nd starts here//
{
if(a==0)
    return 0;
if(a==1)
    return 1;
else
    return (f(a-1)+f(a-2));
}

 

OUTPUT-

fib